Not found component not working in dynamic route segment with nested layout route #4065
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 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
I am also facing the same issue. It is still not resolved
Hey we could not reproduce the issue. I'm going to close this, but if it still happens on the latest versions, feel free to reopen. It may have been fixed by https://github.com/TanStack/router/pull/6120
Sheraff(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
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?