nested notfound
Unanswered
Common Snipe posted this in #help-forum
Common SnipeOP
Hello folks,
I'm running into an issue regarding the notFound method and not-found.tsx within nested routes. I have noticed that when I have a route like domain.com/non-existing-page or domain.com/existing-route/non-existing-page it will work correctly and show the not-found page. However, if I do something like domain.com/non-existing-route/another-non-existing-route/page it will redirect me to the homepage instead of showing a 404 page. Last thing, this all works locally, in regards to properly showing the 404 page for nested routes, this does not work when deployed on vercel. Curent next version - 13.5.2
I'm running into an issue regarding the notFound method and not-found.tsx within nested routes. I have noticed that when I have a route like domain.com/non-existing-page or domain.com/existing-route/non-existing-page it will work correctly and show the not-found page. However, if I do something like domain.com/non-existing-route/another-non-existing-route/page it will redirect me to the homepage instead of showing a 404 page. Last thing, this all works locally, in regards to properly showing the 404 page for nested routes, this does not work when deployed on vercel. Curent next version - 13.5.2
10 Replies
Do you have middleware configured?
Common SnipeOP
we have mw configured for something else. I tried to redirect/rewrite in middleware but It was not redirecting at all on deployment, so I opted to handle the notFound within each page. We have specific pages we're trying to hide before launch, which is why i'm throwing this 404 within each of those pages
@Common Snipe we have mw configured for something else. I tried to redirect/rewrite in middleware but It was not redirecting at all on deployment, so I opted to handle the notFound within each page. We have specific pages we're trying to hide before launch, which is why i'm throwing this 404 within each of those pages
the issue is most likely in your middleware/redirect configuration, that impacts the entire application, but it's hard to know for sure without some code
Original message was deleted
It looks like you're rewriting to a
/404 url on the current path, instead you should be able to just return a 404 statusif (request.nextUrl.pathname.startsWith("/members/")) {
if (!isUserAuthenticated(request.cookies)) {
// Return a 404 response directly instead of rewriting to /404
// This ensures that the server responds with a 404 status code
return new NextResponse("Not Found", { status: 404 });
}
}Common SnipeOP
thanks! I'll try that out
Common SnipeOP
yea, that didn't fix it unfortunately
Common SnipeOP
this isn't using that custom not-found.tsx file though
Common SnipeOP
I can't seem to replicate it either, so probably something we did. Will have to dig into it more. Thanks for the help!
Common SnipeOP
Okay so the issue is actually due to having a dynamic route at root level