-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expose fullPath and to on RouteApi from getRouteApi #6370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1912,6 +1912,28 @@ export class BaseRouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> { | |
| this.id = id as any | ||
| } | ||
|
|
||
| /** | ||
| * The full path of the route, which can be used as the `from` parameter | ||
| * in navigation APIs like `<Link from={routeApi.fullPath}>` or `navigate({ from: routeApi.fullPath })`. | ||
| */ | ||
| get fullPath(): RouteTypesById<TRouter, TId>['fullPath'] { | ||
| if (typeof window !== 'undefined' && window.__TSR_ROUTER__) { | ||
| const route = window.__TSR_ROUTER__.routesById[this.id as string] | ||
| if (route) { | ||
| return route.fullPath as RouteTypesById<TRouter, TId>['fullPath'] | ||
| } | ||
| } | ||
| return this.id as RouteTypesById<TRouter, TId>['fullPath'] | ||
| } | ||
|
Comment on lines
+1915
to
+1927
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Search for __TSR_ROUTER__ type declaration and definition
rg -n "__TSR_ROUTER__" --type=ts -B2 -A2 | head -100Repository: TanStack/router Length of output: 4492 🏁 Script executed: # Look at the actual file to understand the context better
head -n 1940 packages/router-core/src/route.ts | tail -n 50Repository: TanStack/router Length of output: 1403 🏁 Script executed: # Search for fullPath property definition and assignments
rg -n "fullPath" packages/router-core/src/ --type=ts -B1 -A1 | head -150Repository: TanStack/router Length of output: 9142 🏁 Script executed: # Search for documentation about BaseRouteApi.fullPath or routeApi behavior
rg -n "routeApi\.fullPath|BaseRouteApi" --type=ts packages/router-core/src/ -B3 -A3 | head -80Repository: TanStack/router Length of output: 1529 🏁 Script executed: # Check if there are any test cases that document this behavior
rg -n "fullPath" packages/router-core/tests/ --type=ts -B2 -A2 | head -100Repository: TanStack/router Length of output: 7889 🏁 Script executed: # Search for tests involving routeApi or BaseRouteApi
rg -n "routeApi|BaseRouteApi" packages/router-core/tests/ --type=ts -B2 -A2 | head -100Repository: TanStack/router Length of output: 41 🏁 Script executed: # Look for tests that verify fullPath getter specifically
rg -n "\.fullPath" packages/router-core/tests/ --type=ts -B1 -A1 | head -50Repository: TanStack/router Length of output: 41 🏁 Script executed: # Search for usage of routeApi.fullPath or routeApi.to in the codebase
rg -n "routeApi\.(fullPath|to)" --type=ts --type=tsx | head -50Repository: TanStack/router Length of output: 86 🏁 Script executed: # Look for any examples or tests that use BaseRouteApi
find packages -name "*.test.ts" -o -name "*.test.tsx" -o -name "*.spec.ts" | xargs grep -l "fullPath" | head -5Repository: TanStack/router Length of output: 289 🏁 Script executed: # Check if there's SSR-specific documentation or comments about BaseRouteApi
rg -n "SSR|server.*render|isomorphic" packages/router-core/src/route.ts -B2 -A2 | head -50Repository: TanStack/router Length of output: 1425 🏁 Script executed: # Look at the broader context of how fullPath is used in actual route implementation vs API
rg -n "class Route|class BaseRouteApi" packages/router-core/src/route.ts -A15 | grep -A15 "get fullPath"Repository: TanStack/router Length of output: 375 🏁 Script executed: # Check if there's any documentation about BaseRouteApi in comments or README
rg -n "BaseRouteApi" packages/ -B3 -A3 --type=ts | head -80Repository: TanStack/router Length of output: 3463 🏁 Script executed: # Search for any JSDoc updates or issues related to fullPath fallback behavior
rg -n "id.*fallback|fallback.*id" packages/router-core/src/ --type=ts -B2 -A2Repository: TanStack/router Length of output: 1464 Update JSDoc to document SSR fallback behavior. The implementation correctly guards against SSR and falls back to 🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
| * The `to` path of the route, an alias for `fullPath` that can be used | ||
| * for navigation. This provides parity with the `Route.to` property. | ||
| */ | ||
| get to(): RouteTypesById<TRouter, TId>['fullPath'] { | ||
| return this.fullPath | ||
| } | ||
|
|
||
| notFound = (opts?: NotFoundError) => { | ||
| return notFound({ routeId: this.id as string, ...opts }) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesnt work during SSR correctly, so we cant use this
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep makes sense, i looked into it and i dont see a quick win on this one. maybe i should close this out entirely?