Get typesafe child routes list #2197
-
I often find myself making functions that for reusability sake have shorter paths. I may have a function, component, link, etc. like this: const changeSubPage = (subPage: string) => {
navigate({ to: '/page/subpage/' + subPage });
} Is there a way to get that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You could use something like this: type Parent = '/page/subpage/'
type ParentRoute = RouteByPath<RegisteredRouter['routeTree'], Parent>
type ChildRoutes = ParentRoute['types']['children'][keyof ParentRoute['types']['children']]
type ChildPaths = ChildRoutes['path']
const changeSubPage = (subPage: ChildPaths) => {
navigate({ to: `/page/subpage/${subPage}`});
} |
Beta Was this translation helpful? Give feedback.
You could use something like this: