Replies: 1 comment
-
|
In code-based routing, the When a pathless parent has a custom Fix: use the route object directly The most type-safe approach is to reference the route object's // Works — uses the actual computed route ID, TypeScript infers params correctly
useParams({ from: groupItemRoute.id })Or export the ID instead of the path: // Define once
export const groupItemRoute = createRoute({ path: groupItemRoutePath, getParentRoute: () => groupRoute })
export const GROUP_ITEM_ROUTE_ID = groupItemRoute.id // inferred as '"id/path"'
// Use everywhere
useParams({ from: GROUP_ITEM_ROUTE_ID })Why not The The docs mention this in the Route IDs section, but agreed it's worth a clearer callout in the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using code-based routing with nested routes:
Calling useParams in a component using the path will throw an error:
useParams internally uses the route's id, not its path. When using nested routes, the id is generated based on the parent route's id and the child route's path. Because of this, it becomes impossible to reuse route path constants—you have to either import the route and use its id or search through router.routesByPath. Is this the expected behavior? It would be good if this were mentioned in the documentation
Beta Was this translation helpful? Give feedback.
All reactions