Skip to content

fix: resolve MatchRoute return types for pathless (layout) routes - #7571

Open
EduardF1 wants to merge 3 commits into
TanStack:mainfrom
EduardF1:fix/match-route-pathless-types
Open

fix: resolve MatchRoute return types for pathless (layout) routes#7571
EduardF1 wants to merge 3 commits into
TanStack:mainfrom
EduardF1:fix/match-route-pathless-types

Conversation

@EduardF1

@EduardF1 EduardF1 commented Jun 7, 2026

Copy link
Copy Markdown

Description

Fixes #6011

Currently, router.matchRoute returns a type of false when matching against paths contained within pathless (layout) routes (e.g. _pathless/nested/$id). The runtime behavior is correct, but the generic TResolved resolution fails to extract the underlying string type when passing through NoInfer via the Layout masking.

This patch adds a string union extraction step on TResolved, ensuring the generic constraint successfully unwraps the pathless definition and provides proper TS intellisense (ResolveParams) without evaluating to never or false.

Testing

Verified TS compiler locally.

Summary by CodeRabbit

  • Bug Fixes
    • Improved type safety for route matching results, allowing plain string inputs for route matching and ensuring route parameter types are correctly narrowed for pathless (layout) routes.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 98895663-8027-44b8-82e6-d0a9c30aace5

📥 Commits

Reviewing files that changed from the base of the PR and between 36e2fb6 and f1890e6.

📒 Files selected for processing (1)
  • .changeset/matchroute-pathless-return-types.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/matchroute-pathless-return-types.md

📝 Walkthrough

Walkthrough

The PR broadens MatchRouteFn typing to accept any string for TFrom and narrows the resolved route id with Extract<TResolved, string>. It also adds a patch changeset documenting the return-type behavior change for pathless layout routes.

Changes

MatchRouteFn Type Signature Update

Layer / File(s) Summary
Type signature and changeset update
packages/router-core/src/router.ts, .changeset/matchroute-pathless-return-types.md
TFrom now accepts any string, RouteById is narrowed with Extract<TResolved, string>, and a patch changeset records the updated MatchRoute/useMatchRoute return-type behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hopped where types once strained,
Then string and Extract aligned the lane.
Pathless routes now find their way,
With params that types can safely say! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing MatchRoute return types for pathless routes.
Linked Issues check ✅ Passed The type-only changes address #6011 by preserving params for pathless layout routes and keeping runtime behavior unchanged.
Out of Scope Changes check ✅ Passed The diff stays focused on the reported type fix and its changeset documentation, with no unrelated feature work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant