Child route incorrectly matches in beta 70
Describe the bug
In beta 70 a child route of / matches on just /, but the /test route never matches.
const indexRoute = new Route({
getParentRoute: () => rootRoute,
path: '/',
component: () => {
return (
<div className="p-2">
<h3>Index</h3>
<Outlet />
</div>
);
},
});
const childOfIndexRoute = new Route({
getParentRoute: () => indexRoute,
path: 'child',
component: () => {
return (
<div className="p-2">
<h4>Child of index route</h4>
</div>
);
},
});
const notChildOfIndexRoute = new Route({
getParentRoute: () => rootRoute,
path: 'test',
component: () => {
return (
<div className="p-2">
<h4>Child of index route</h4>
</div>
);
},
});
const routeTree = rootRoute.addChildren([
indexRoute.addChildren([childOfIndexRoute]),
notChildOfIndexRoute,
]);
In beta 69 it is the opposite problem, the child route never matches, but the peer "/test" route matches correctly.
Your Example Website or App
https://stackblitz.com/edit/tanstack-router-zhfoj7?file=src/main.tsx
Steps to Reproduce the Bug or Issue
- On launch notice that the
/route is showing "Child of index route" - Go to
/test, notice that the child route no longer renders, but the index route incorrectly renders - Update package.json to use beta.69.
- Go to the
/route and notice that index render successfully - Go to
/childand notice it renders successfully - Go to
/testand notice that the test route is not rendered
Expected behavior
I would expect / to render just the index route, /child to render the index route plus the content for the child route. I would then expect /test to render only the test route without index content.
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Edge
- Version: 109
Additional context
No response
I’m actually reworking the matching right now. I’ll push a fix soon.
For the index route, instead of path: '/' if it's id: '/'
then it would load the notChildOfIndexRoute correctly.
Also, with this the index route would load the first child route as default.
Matching should be much better now. It's all described here, too:
- https://tanstack.com/router/v1/docs/guide/route-paths
- https://tanstack.com/router/v1/docs/guide/route-matching