-
-
Notifications
You must be signed in to change notification settings - Fork 458
return a static 404 page when a route cannot be found #432
return a static 404 page when a route cannot be found #432
Conversation
Thanks again 🙌 I wonder if we could make this change backward compatible the same way next announced it,
Also, do you know if 404.html is always produced on build, even when users are still using |
Looks like it is not produced in that case. The build output suggests that for that scenario (_error defined, but no 404) the 404 page should be SSR'ed from a lambda. damn |
In the default-handler you could check the This is an example
|
FYI - I've PR'ed a fix to remove the default statusCode from the response. #437 |
Nice, I've done that in a local commit too, but I need to finish writing/fixing tests. Will come back to finish this PR later this week. |
6cc6bf0
to
9b95ec6
Compare
9b95ec6
to
d6b7aa8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍 I'll be testing it tonight.
fixes #378
According to https://nextjs.org/docs/advanced-features/custom-error-page#404-page the 404 page is "statically generated at build time". As such, it cannot be SSR'ed and is expected to be returned when a route cannot be found. Whereas _error.js can only be SSR'ed and is expected to handle other kinds of errors.
Impact
This approach will be a slight regression for those looking to localize their 404 pages. On the server side, one could previously read the language cookie (or something similar) and set the page locale based on that. Always returning a static 404.html page means that a client-side implementation will be required which is going to feel bad.... or maybe don't even worry about localizing 404 pages. Next.js does not currently provide a good way to localize apps. :(