Skip to content

router.matchRoute doesn't resolve TS type with pathless (layout) routes #6011

@vladrasenko

Description

@vladrasenko

Which project does this relate to?

Router

Describe the bug

When trying to use the router.matchRoute function with a path that is contained within a pathless route, the resulting match result is typed to false. Running the function returns the correct value. It's only TS issue.

Your Example Website or App

https://stackblitz.com/edit/github-trezcbpr?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

  1. Create route routes/_pathless/route.tsx
  2. Create nested route routes/_pathless/nested/$id.tsx
  3. Call router.matchRoute (use global router instance) with "/nested/$id.tsx"
  // match has type 'false'
  const match = router.matchRoute({
    to: '/nested/$id',
    params: {
      id: 'someId',
    },
  });

  return match && match.id; // Property 'id' does not exist on type 'never'.(2339)

Expected behavior

return type is false | ResolveParams<"/_pathless/nested/$id"> instead of false

Screenshots or Videos

Image Image Image

Platform

  • Router Version: 1.139.12
  • OS: macOS
  • Browser: Chrome
  • Browser Version: 142.0.7444.176
  • Bundler: vite
  • Bundler Version: 7.1.7

Additional context

Maybe the same reason as at #1680

Metadata

Metadata

Assignees

No one assigned

    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