[Bug?]: v7 useMatches not working as expected in route module #12428
-
I am not sure if this issue also persists when using the file system routing convention but I noticed it whilst using the Route Configuration convention. This is my routes as defined below whilst using routes config. import {
index,
layout,
prefix,
route,
type RouteConfig,
} from '@react-router/dev/routes'
export default [
layout('./routes/public/layout.tsx', [
index('routes/public/home.tsx'),
route('forgot-password', 'routes/public/forgot-password.tsx'),
]),
...prefix('app', [
layout('./routes/dashboard/layout.tsx', [
index('./routes/dashboard/route.tsx'),
layout('./routes/dashboard/account/layout.tsx', [
...prefix('account', [
index('./routes/dashboard/account/route.tsx'),
route('password', './routes/dashboard/account/password/route.tsx'),
]),
]),
]),
]),
] satisfies RouteConfig I have added I am trying to add breadcrumbs to my pages so for each of the handle functions in the 3 pages, I have added some breadcrumb information. See the example below for the breadcrumb information for the route: //./routes/dashboard/account/route.tsx
export const handle = {
breadcrumb: true,
href: '/app/account',
text: 'Account',
} But when I run [
{
"id": "root",
"pathname": "/",
"params": {},
"data": {
"toastMessage": null,
"toastType": null,
"theme": null
}
},
{
"id": "routes/dashboard/layout",
"pathname": "/",
"params": {},
"data": {
"defaultSidebarOpen": true,
}
},
{
"id": "routes/dashboard/account/layout",
"pathname": "/",
"params": {},
"data": null
},
{
"id": "routes/dashboard/account/password/route",
"pathname": "/app/account/password",
"params": {},
"data": null,
"handle": {
"breadcrumb": "/app/account/password",
"href": "/app/account/password",
"text": "Password"
}
}
]
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I also tried this in filebased routing and it's the same result, I am only seeing the handle function from the current page I have visited. The handle from all previous pages (in the nested route) does not show. |
Beta Was this translation helpful? Give feedback.
-
Based on the route you mentioned, that behavior is correct. Every file you mention is a leaf route (it has no routes nested inside). You need to add the For example if you're on
But if you go navigate to
See how the password route file is not matching anymore, so you won't get it, but the first three files are matching. Also if you go to
Now the third one ( So if you want to get the |
Beta Was this translation helpful? Give feedback.
Based on the route you mentioned, that behavior is correct. Every file you mention is a leaf route (it has no routes nested inside). You need to add the
handle
to the layout routes too.For example if you're on
/app/account/password
you will get the matches of these files:app/root.tsx
app/routes/dashboard/layout.tsx
app/routes/dashboard/account/layout.tsx
routes/dashboard/account/password/route.tsx
But if you go navigate to
/app/account
you will get the matches of these other files:app/root.tsx
app/routes/dashboard/layout.tsx
app/routes/dashboard/account/layout.tsx
app/routes/dashboard/account/route.tsx
See how the password route file is not matching anymore, so you won't get it, bu…