Accessing Route.fullPath from outside the route file (for relative navigation in other components)
I have a layout route with a sidenav that has links to child routes. When the component lives in the route file, I can use
This is great because:
- I don't need to repeat
- It's type-safe
- Relative navigation works correctly from any child route (e.g., clicking from
The problem: I want to extract
Current workarounds (not ideal):
1. Hardcode the path string:
2. Export from route file:
What I'm hoping exists:
- A way to get
- Some other pattern for type-safe relative navigation from extracted components
Is there a recommended approach for this?
Route.fullPath with relative to and everything works great:This is great because:
- I don't need to repeat
params={{ reviewId }} on every link- It's type-safe
- Relative navigation works correctly from any child route (e.g., clicking from
/reviews/123/overview/details correctly goes to /reviews/123/analytics, not /reviews/123/overview/details/analytics)The problem: I want to extract
Sidenav to its own file for code organization. When I use getRouteApi, I lose access to fullPath:Current workarounds (not ideal):
1. Hardcode the path string:
from="/reviews/$reviewId" — loses type safety, have to manually strip pathless groups like _protected2. Export from route file:
export const fullPath = Route.fullPath — works but feels redundantWhat I'm hoping exists:
- A way to get
fullPath from getRouteApi(), or- Some other pattern for type-safe relative navigation from extracted components
Is there a recommended approach for this?