Migration from `NotFoundRoute` to `notFoundComponent`
I'm trying to follow the migration guide for NotFoundRoute in order to move on notFoundComponent.
I have a "global" Not Found Error, which needs to be renderer with the RootRoute Layout. When I try to use notFoundComponent on rootRoute, the component is not displayed inside the Layout when it was well displayed with NotFoundRoute.
This is very strange because the migration guide says : "When using NotFoundRoute, you can't use layouts. notFoundComponent can be used with layouts."
Thank's for your effort the lib is very good !
12 Replies
variable-lime•2y ago
Hi there! I made the pull request that adds these new APIs
By "notFoundComponent can be used with layouts" I mean that if a not-found does happen, the
component of the route is replaced with the notFoundComponent in whatever <Outlet /> is rendering it. This means that in the case of the root route (where there is no <Outlet />), the notFoundComponent is a direct replacement for component. Before, with NotFoundRoute, it sometimes would not display correctly when using layouts.
If you want to persist your root layout, you could extract the layout elements to its own component and wrap both the route component and notFoundComponent in it. Alternatively, you can put the layout in InnerWrap (although you won't get the data loading functionality).
Example for method 1:
Before:
After:
sensitive-blueOP•2y ago
Thank you for your quick response. Unfortunately, I am not convinced by these two solutions. I think it's important to be able to render notFoundComponent inside the Layout of the route it's declared
variable-lime•2y ago
My rationale for not having the
notFoundComponent render inside the layout of the current route (replacing the <Outlet /> inside it) is that the component that renders the outlet often uses loader data, which can throw not-found errors. It works the same for the root route in order to keep the behavior consistent between all types of routes.
Maybe a layout option on route that wraps the route in a static, not-dependent-on-loader component could help this.sensitive-blueOP•2y ago
Ok it's a good point for route with loader. Where do you want to add layout option ?
What do you think to something like this :
I would prefer something very close to component with option but hard to pass option
variable-lime•2y ago
(an idea) like:
sensitive-blueOP•2y ago
Why we can not use Layout with Outlet ?
variable-lime•2y ago
It probably could, but I'm not too sure how to implement it
sensitive-blueOP•2y ago
I think it's very important to make this possible. Changing the layout for this usecase do not appeared to be a good decision
My RootRoute do not display something, i just use it to add my Layout
metropolitan-bronze•2y ago
Unless I'm misunderstanding you, I have accomplished this with the following:
genetic-orange•2y ago
This can be trivially implemented with just a react component that accepts children?
sensitive-blueOP•2y ago
something like that
But yes this is well understood but i do not like mutate display
genetic-orange•2y ago
?