Next.js Discord

Discord Forum

404 page for dynamic routes

Unanswered
Masai Lion posted this in #help-forum
Open in Discord
Masai LionOP
I am currently using app router and am trying to make dynamic routes based off of a list of files. How can I make it so if none of the urls (which would be the same as the file name) match any files, it would be a 404 page not found?

4 Replies

Barbary Lion
@Masai Lion the 404 page is shown by default if someone navigates to a route that does not exist
@Barbary Lion <@210245222238519296> the 404 page is shown by default if someone navigates to a route that does not exist
Masai LionOP
im using a dynamic page though so technically every route would exist for the page directory
Barbary Lion
@Masai Lion you would have to check if it exists, ideally by calling an API route, and if it doesn't, push the error page to the router