Skip to content

Layout routes cause optional params to fail to match #5912

@CynicalBusiness

Description

@CynicalBusiness

Which project does this relate to?

Router

Describe the bug

Taking the example route from the documentation of posts/{-$category}, this is documented to match both /posts and /posts/category.

While this normally works as expected, if a "route" component exists, such as this:

posts/
  {-$category}.tsx
  route.tsx

/posts now fails to match anything. The route.tsx is rendered but the outlet is just left empty. If route.tsx is removed, the category route is rendered as expected.

This looks related to things like #5799 and #5635, but the fix attached to both those issues seems to have already landed and did not resolve this issue.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-3ccfbxyn?file=src%2Froutes%2Fposts.%7B-%24category%7D.tsx

Steps to Reproduce the Bug or Issue

  1. Visit the StackBlitz link (modified from the "Basic (file-based)" example)
  2. Navigate to "Posts"
  3. Observe that "no category" fails to match, but categories A and B are fine.
  4. Rename/delete posts.route.tsx and observe the "no category" route rendering fine.

Expected behavior

The URL /posts matches posts/{-$category}.tsx as expected/documented.

Screenshots or Videos

Example from the router devtools in my app:
Image

Despite the route being /workspaces/some-workspace-id, the {-$folderId} route does not match.

Platform

  • Router / Start Version: 1.136.17
  • OS: Windows
  • Browser: Both Chrome/Edge
  • Browser Version: >= 142.0
  • Bundler: vite
  • Bundler Version: 7.1.7

Additional context

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions