Static Route also calling fetch request on Dynamic route
Answered
Masai Lion posted this in #help-forum
Masai LionOP
I'm using Next.js 14 App router and I seem to be in a scenario where my static predefined route is triggering API calls from dynamic routes when I load the page.
When running the project in development mode I can see through the terminal window the requests that are being triggered.
It was my understanding that a specific route like my example would override any dynamic routes. so I'm a bit confused as to why these extra calls are happening.
(blue box is the route im loading, orange is the one that is also being called
When running the project in development mode I can see through the terminal window the requests that are being triggered.
It was my understanding that a specific route like my example would override any dynamic routes. so I'm a bit confused as to why these extra calls are happening.
(blue box is the route im loading, orange is the one that is also being called
Answered by Masai Lion
After more debugging it seems that the additional requests were being caused by missing sources, seems that there was no error thrown and i was trying to load video data that didn't exist.
8 Replies
Its loading the one from the "api" folder
Not the [slug]/page.tsx
Masai LionOP
api/get_page only gets called on the [slug] > page.tsx template though? The other page gets its data from api/get_directorsim trying to load the
/directors so i wouldnt expect the get_page api route to be loadedClear the console, check again and this time only load /directors. If it still calls /api/get_page then check the code again. Maybe one of the components is calling get_page?maybe the template/layout is calling get page or maybe the get directors route handler is calling get page
Masai LionOP
it looks like there is something in a nested component causing the issue, when I comment out that module the pages load as expected, I'll have to see if i can pinpoint where things have gone a bit sideways
Masai LionOP
After a bit of debugging and stripping the module back a bit I've narrowed it down to the preload attribute on a video tag, if the value is anything other than "none" it triggers the additional GET requests. you can see in the screenshots the difference in the terminal window based on the preload value.
Masai LionOP
After more debugging it seems that the additional requests were being caused by missing sources, seems that there was no error thrown and i was trying to load video data that didn't exist.
Answer