T
TanStack2y ago
other-emerald

Route branch based typing: is it possible?

I've got an app with two main routes, each with nested routes.
const routeTree = rootRoute.addChildren([
homeRoute,
branchA.addChildren([child1, child2, child3]),
branchB.addChildren([child4, child5, child6]),
])
const routeTree = rootRoute.addChildren([
homeRoute,
branchA.addChildren([child1, child2, child3]),
branchB.addChildren([child4, child5, child6]),
])
Is there any way to tell TS to ignore certain branches of the routing heirarchy? If I know I am in branchB, but I just don't know which child, I'd like to not have to contend with all the search types for all of branchA as well. In my case, the types are incompatible, such that search={x => x} actually fails if I cannot provide both to and from. What I'd like to do, conceptually, is something like this:
<Navigate
within={branchA.id} // This line is the idea
search={x => ({...x, page: x.page + 1})}
/>
<Navigate
within={branchA.id} // This line is the idea
search={x => ({...x, page: x.page + 1})}
/>
2 Replies
rising-crimson
rising-crimson2y ago
where are the search types defined? on branchA route or on child1 etc?
other-emerald
other-emeraldOP2y ago
Both (though children do inherit from ancestors, so effectivly: just the different children). It's kind of like two separate applications, housed in the same SPA. And my example is simplified. In reality there are many more children, some with nested routes of their own.

Did you find this page helpful?