useMatches doesn't return handle data from all Index routes #10412
Replies: 1 comment
-
Example 1 is correct since you're not matching Example 2 is missing Example 3 is how I'd expect this to work if you need specific index routes when not matching deeper.
I'm not quite sure what's unclear here? <Route element={<GlobalLayout title="Example 3" />}>
<Route path="/" handle={{ crumb: "Home Crumb" }}>
<Route index element={<h2>Home</h2>} />
<Route path="nested-1" handle={{ crumb: "Crumb 1" }}>
<Route index element={<h2>Nested 1</h2>} /> ❌ Not matched for /nested-1/nested-2
<Route path="nested-2" handle={{ crumb: "Crumb 2" }}> ✅ Matched for /nested-1/nested-2
... |
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.
-
I've been playing with nested routes and breadcrumbs and i think there's something I'm missing, if it's not a bug.
I made a reproduction: https://codesandbox.io/s/react-router-breadcrumb-v1-bjxuqj?file=/src/App.tsx
Example 1
I'm setting the breadcrumb data in the
index
route handle, butuseMatches
doesn't return the data for all the routes, only for the current route. Is this expected and the data should be placed in the parent route handle instead?Example 2
The data is returned, but the route doesn't change. I guess that's because If the parent route matched exactly, it will render a child index route or nothing if there is no index route.
Example 3
This one works as i was expecting, but it took me some time really figure out. I needed to set the data in the handle of the parent route, the docs doesn't say anything about this.
Beta Was this translation helpful? Give feedback.
All reactions