TanStack / TanStack/router

Fuzzy match for deep links with missing parent route not allowed by types

Open
#3,009 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Router

Describe the bug

When trying to fuzzily match deep paths at a level that does not have a route, the types do not allow it.

  // this should be allowed when on the `/very/deep/path` route
  useMatchRoute().matchRoute({ to: '/very', fuzzy: true });
Your Example Website or App

https://stackblitz.com/edit/github-t9tvnutk?file=src%2Froutes%2Fvery%2Fdeep%2Fpath.tsx,src%2Froutes%2F__root.tsx

Steps to Reproduce the Bug or Issue
  1. Create deep routes without a parent route
  2. Try to match a common parent route of those routes

The types prohibit this match: to is flagged as invalid and the returned type is false when.
The runtime allows this match: no runtime error, and the returned value is an object like { '**': 'deep/path' }

Expected behavior

Types should not prohibit this.

Screenshots or Videos

No response

Platform
  • OS: Win11
  • Browser: Chrome
  • Version: 131.0.6778.140
Additional context

Is this because there is no "route" to match?
Either way, the types do not match the runtime behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the type mismatch in the linked StackBlitz using src/routes/very/deep/path.tsx and src/routes/__root.tsx. Start from the useMatchRoute().matchRoute call and compare the declared route type with the runtime result for the missing parent path. Done means the deep-link example type-checks and preserves the runtime match object.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.