Not found component not working in dynamic route segment with nested layout route
Which project does this relate to?
Router
Describe the bug
A pathlessLayoutRoute within a Dynamic route segment does not trigger the parent routes' notFoundComponent, even from the root. Instead it uses the "TanStack Router's overly generic defaultNotFoundComponent"
Your Example Website or App
https://stackblitz.com/edit/github-qz55lodc?file=src%2Froutes%2Ftest.tsx
Steps to Reproduce the Bug or Issue
- With the following file-based setup, extended from one found in the docs:
routes/
βββ $postId/
βββ _postPathlessLayout/
β βββ works.tsx
βββ _postPathlessLayout.tsx
- And a
notFoundComponentset on both_root.tsx&_postPathlessLayout.tsx - Check that navigating to a real page works:
/my-post-id/worksand see the expected page. - Try to navigate to a page that does not exist, like
/my-post-id/not-exists. It will show "TanStack Router's overly generic defaultNotFoundComponent", rather than picking the customnotFoundComponents which are set on the parent_root.tsxor_postPathlessLayout.tsxroutes
Expected behavior
I would expect the _postPathlessLayout.tsx notFoundComponent to be shown.
Screenshots or Videos
No response
Platform
- OS: [macOS]
- Browser: [Chrome]
- Version: [1.117.1]
Additional context
No response
I'm running into this exact same issue using React 19 and the latest version of @tanstack/router. This is my first time working with this router, so I donβt have a reference point from previous versions to compare behavior. Is this a recent regression or has it always worked this way?
I have this issue as well. But not only for pathless routes.
Same here. I have a dynamic route, but its index isn't made (i didn't made) but others are like /abc/a is made, /abc/b is made but not /abc, navigating to /abc will show routers warning and its <div>Not Found</div> on the page, not my custom not found. I am using devinxi start.
Same.
Also the issue and the things that is confusing is that /$postId route should not be routable. But it still returns an empty page and not a 404 error