T
TanStack2w ago
continuing-cyan

Default child route for layout route

I have a layout route that renders some tabs that switch between several child routes. Let's say we have /parent, then /parent/tab1 and /parent/tab2. Now, I don't want the index route to ever be rendered - the user should be redirected to /parent/tab1 by default if they attempt to visit /parent. I can achieve this by throwing a redirect in the beforeLoad and looking at the location there, but this is not typesafe. Can I find out if no child route is matched? Or can I provide a fallback for the Outlet? I've looked at the documentation and didn't find anything.
1 Reply
rival-black
rival-black2w ago
beforeLoad has matches object that you can use to get "latest" match (meaning either this route or child route, assuming this route has only 1 level of children) and then compare match.routeId with Route.id. I am not sure if this is a good pattern to directly use Route though

Did you find this page helpful?