router icon indicating copy to clipboard operation
router copied to clipboard

Not found component not working in dynamic route segment with nested layout route

Open sacha-c opened this issue 8 months ago β€’ 3 comments

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

  1. With the following file-based setup, extended from one found in the docs:
routes/
β”œβ”€β”€ $postId/
β”œβ”€β”€ _postPathlessLayout/
β”‚   β”œβ”€β”€ works.tsx
β”œβ”€β”€ _postPathlessLayout.tsx
  1. And a notFoundComponent set on both _root.tsx & _postPathlessLayout.tsx
  2. Check that navigating to a real page works: /my-post-id/works and see the expected page.
  3. 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 custom notFoundComponents which are set on the parent _root.tsx or _postPathlessLayout.tsx routes

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

sacha-c avatar Apr 28 '25 11:04 sacha-c

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?

mariana-truta-zg avatar Apr 29 '25 16:04 mariana-truta-zg

I have this issue as well. But not only for pathless routes.

borstessi avatar May 28 '25 10:05 borstessi

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.

MuntasirSZN avatar Jun 14 '25 09:06 MuntasirSZN

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

leonardbiofi avatar Aug 26 '25 14:08 leonardbiofi