router
router copied to clipboard
router.matchRoute doesn't resolve TS type with pathless (layout) routes
Which project does this relate to?
Router
Describe the bug
When trying to use the router.matchRoute function with a path that is contained within a pathless route, the resulting match result is typed to false. Running the function returns the correct value. It's only TS issue.
Your Example Website or App
https://stackblitz.com/edit/github-trezcbpr?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue
- Create route
routes/_pathless/route.tsx - Create nested route
routes/_pathless/nested/$id.tsx - Call
router.matchRoute(use global router instance) with"/nested/$id.tsx"
// match has type 'false'
const match = router.matchRoute({
to: '/nested/$id',
params: {
id: 'someId',
},
});
return match && match.id; // Property 'id' does not exist on type 'never'.(2339)
Expected behavior
return type is false | ResolveParams<"/_pathless/nested/$id"> instead of false
Screenshots or Videos
Platform
- Router Version: 1.139.12
- OS: macOS
- Browser: Chrome
- Browser Version: 142.0.7444.176
- Bundler: vite
- Bundler Version: 7.1.7
Additional context
Maybe the same reason as at https://github.com/TanStack/router/issues/1680
Hey! Is this issue still available? I’d love to work on it