TanStackT
TanStack9mo ago
9 replies
ordinary-sapphire

Layouts in file-based routing: can they be nested inside folders?

Hi! I have a question about TanStack Router and file-based routing.

If I use file-based routing, do layouts always have to live at the root of the /routes folder?

For example, in Next.js, you can organize files like this:
/app
  layout.tsx
  page.tsx
  /dashboard
    layout.tsx
    page.tsx


Currently, I'm trying to do the same thing on Tanstack Start like this:
/routes
  __root.tsx
  index.tsx
  /_dashboard-layout
    _dashboard-layout.tsx
    dashboard.index.tsx


In this structure, each folder can have its own layout.tsx scoped to its pages.
Is a similar structure possible with TanStack Router, or do layouts need to be declared only at the top level?

Thanks a lot!
Was this page helpful?