Dynamic catch-all at the root and expecting a not-found response for any non-catch-all route
Unanswered
Mini Rex posted this in #help-forum
Mini RexOP
Not really sure how to phrase this question and can't quite discern what the intended behaviour is from the documentation, but here goes.
I have a minimal file structure in the app directory as follows
The behaviour seems to be that if I navigate to an API route that doesn't exist (e.g. /api/third) it will then render the page from [...slug]/page.js
Similarly this produces the same result
I would like to have it render one of the two "not-found" files instead, as I would have expected that the slug shouldn't cover the API route and should only be handling any undefined root-level nested routes
Is this something that's possible by restructuring my routes while keeping a top-level catch-all for non-API routes?
I have a minimal file structure in the app directory as follows
-app
-[...slug]
-page.js
-api
-first
-route.js
-second
-route.js
-not-found.js
-page.js
-not-found.jsThe behaviour seems to be that if I navigate to an API route that doesn't exist (e.g. /api/third) it will then render the page from [...slug]/page.js
Similarly this produces the same result
-app
-[slug]
-page.js
-[...nestedSlug]
-page.js
-api
-first
-route.js
-second
-route.js
-not-found.js
-page.js
-not-found.jsI would like to have it render one of the two "not-found" files instead, as I would have expected that the slug shouldn't cover the API route and should only be handling any undefined root-level nested routes
Is this something that's possible by restructuring my routes while keeping a top-level catch-all for non-API routes?
5 Replies
Mini RexOP
Photo overview of the routes I'm describing
this is the desired behaviour
you have to use
notFound inside your catch-alls to get the 404 pageMini RexOP
Figured as much, might just have to change to
/page/[...slug] in order for it to leave the API route alone then.