TanStack / TanStack/router

Expose id on LazyRoute

Open
#5,167 2 comments 0 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

I found this wonderful demo from Balastrong where he uses the RouteId to do some create work with hooks. I want to replicate something similar in my project, but I discovered that the id property is not exposed on LazyRoute instances. It can be accessed with Route.options.id, but as it is stored as a string, it loses all typing. Therefore I opened this issue hoping that the property can be made available on lazy routes.

Your Example Website or App

https://stackblitz.com/edit/github-kv47mrvu?file=src%2Froutes%2Fthisislazy.lazy.tsx

Steps to Reproduce the Bug or Issue

When looking at the source code of the LazyRoute class defined in the react-router package, the options object is defined as:

{
    id: string
  } & LazyRouteOptions

Because of this, all typing is lost and it cannot meaningfully be used.

Expected behavior

A simple solution is to add the following method to the LazyRoute class:

get id(): {
   return this.options.id as TRoute['id']
}

Screenshots or Videos

No response

Platform
  • Router / Start Version: 1.131.44
  • OS: -
  • Browser: -
  • Browser Version: -
  • Bundler: vite
  • Bundler Version: -
Additional context

No response

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

Inspect the LazyRoute class in the react-router package and reproduce the typing issue using the linked StackBlitz example. Expose the route id with its declared type, then verify that lazy route consumers can access the typed id instead of reading options.id as a string.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.