errorElement never gets called when child Routes are in a <Routes>
element
#10350
-
In a react-router app with nested routes, I have a component that looks like this: function Example() {
return (
<Routes>
<Route
path="*"
errorElement={<GotStartedRoutesError />}
element={
<NavLayout>
<Routes>
<Route
path="*"
element={
<GotStarted>
<Navigate to="/hosts" replace={true} />
</GotStarted>
}
/>
<Route
path="hosts/*"
element={
<GotStarted>
<HostsRoot />
</GotStarted>
}
/>
<Route path="*" element={<NotFound />} />
</Routes>
</NavLayout>
}
/>
</Routes>
);
} My problem is that react-router treats the It would be great to document this if this is intentional, plus adding tests, since https://reactrouter.com/en/main/route/error-element#bubbling leads me to believe that I can just have a root error element and call it a day, rather than requiring that every Routes has a root Route that applies an errorElement to each route |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I think my preference in that case would just to allow passing an |
Beta Was this translation helpful? Give feedback.
-
#10372 I have learned from #10317 and #10021 that Hopefully #9996 will morph into a useful replacement |
Beta Was this translation helpful? Give feedback.
There's a bit of confusion around the usage of
<Routes>
and<RouterProvider>
. I tried to clarify a bit in this comment and this comment, and we will work on improving the docs around this as well.But
<Routes>
is definitely supported when usingcreateBrowserRouter
- that's the key to the ability to incrementally migrate your app.However, you cannot include an
errorElement
on any<Route>
's below a descendant<Routes>
though, as is shown in the example above.