Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Better 404 Error handling #203

Closed
sergiodxa opened this issue Jun 19, 2021 · 2 comments
Closed

Idea: Better 404 Error handling #203

sergiodxa opened this issue Jun 19, 2021 · 2 comments

Comments

@sergiodxa
Copy link
Member

Right now there is a routes/404 route which is used to render a not found UI for any request against a route not matching the current routes.

If a route has parameters it will need to handle a case where the resource was not found (e.g. in users/$id the user 10 may not exists), in this case you need to redirect to /404 and change the URL or return a response with the 404 status and an empty response and then in the component conditionally render the not found UI or the actual user, additionally you may need to change the links and meta based on the returned response, to load the styles of your generic 404 page and change the title and meta tags for a not found case.

Idea

Remix could export a NotFoundError class extending from Error, if a loader throw this error instead of the error boundary of the route it should render the routes/404 route with the links and meta of that file.

In most cases that will be enough, but if you want to customize the UI of the 404 status for a certain route then Remix could let you export a NotFound component which will be rendered instead of the normal component, in this case you may not need to load different stylesheets since the error UI is custom and most probably reuse parts of the normal UI, for the meta you can receive the error as the data and conditionally change the title, this is ok in this case because you want something more custom.

@andrelandgraf
Copy link
Contributor

I think it would be cool if you could just create a 404 file at any level of the routes/ folder and a 404 bubbles up until a 404 route is found (latest would be the routes/404). The 404 could then render into the <Outlet /> like any other component which would be a great way to show custom 404s on any level while reusing the current route layout.

@sergiodxa
Copy link
Member Author

This is solved with the CatchBoundary export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants