Replies: 2 comments
-
I agree that allowing route handlers to trigger a 404 page render would be very useful, especially for dynamic routes. The current workaround of returning a 404 status without a page render is not ideal. Of the options proposed, I think Rendering the actual 404 page instead of just returning a status code would also help avoid confusing empty responses in certain situations. For example, in authentication flows using OAuth - triggering a proper 404 would make errors and unexpected states clearer to the user. Overall this would be a great quality-of-life improvement for developers working with Next.js apps. I'm excited about the possibility of having this functionality added! Let me know if there's anything I can help with to move this proposal forward. Related |
Beta Was this translation helpful? Give feedback.
-
I just ran into this issue as well. My use case is that I'm proxying a file response from an external server, but would like to show a friendly 404 rather than the default browser one. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Allowing a route handler to trigger a render of the not-found page.
Non-Goals
Customising the 404 page from the route handler.
Background
Some route handlers with dynamic routes, e.g.
/app/[slug]/route.ts
, might want to return a 404 for some values of the segment. They can currently do this:However, that won't render the not-found page.
Proposal
Support either:
notFound()
in route handlers, orNextResponse.notFound()
, orBeta Was this translation helpful? Give feedback.
All reactions