Skip to content

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

Closed

Description

@sacha-c

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

Activity

  1. mariana-truta-zg commented on Apr 29, 2025

    @mariana-truta-zg

    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?

  2. borstessi commented on May 28, 2025

    @borstessi

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

  3. MuntasirSZN commented on Jun 14, 2025

    @MuntasirSZN

    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.

  4. leonardbiofi commented on Aug 26, 2025

    @leonardbiofi

    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

  5. rahulxdemon commented on Jan 14, 2026

    @rahulxdemon

    I am also facing the same issue. It is still not resolved

  6. Sheraff commented on Jul 14, 2026

    @Sheraff
    Collaborator

    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 #6120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions