TanStackT
TanStack2y ago
2 replies
sad-indigo

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]),
])


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})}
/>
Was this page helpful?