TanStackT
TanStack9mo ago
4 replies
full-green

Layout route

I have a route /account that has two children so /account/settings and /account/edit.
I'm using file based routing:
routes/
├── account/
│   ├── route.tsx
│   ├── settings.tsx
│   ├── edit.tsx

What I want is the route /account to not be reachable but only child routes and keep account in the url.
I tried to redirect to /account/settings in the route.tsx file in a loader or beforeLoad but it gives me an error of too many redirects so I ended up with this solution so if user want to access /account the notFound component is rendered

routes/
├── _account/
│   ├── route.tsx
│   ├── account/
│      ├── settings.tsx
│      ├── edit.tsx

Not sure that this is the right way, maybe someone could give me some advice here ?
thanks
Was this page helpful?