Skip to content

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions