T
TanStack8mo ago
continuing-cyan

_index.tsx layout?

am I doing something wrong or is it not possible to add layout to index.tsx using _index.tsx? would be cool to keep the layout in the same dir as the route itself
4 Replies
optimistic-gold
optimistic-gold8mo ago
that's not how pathless routes work in router the only way to keep them next to each other is
foo/
index.tsx
route.tsx
foo/
index.tsx
route.tsx
put the layout into route.tsx
continuing-cyan
continuing-cyanOP8mo ago
I don't really need it, but I think it's an interesting case, do you know how to add a layout for /? if I create src/routes/_index.tsx then it creates a route with this name (/_index)
optimistic-gold
optimistic-gold8mo ago
either put it in the root route or create a _foo layout and nest under it
_foo.tsx
_foo/
index.tsx
_foo.tsx
_foo/
index.tsx
eager-peach
eager-peach8mo ago
To add to this, you can do
_foo/
- index.tsx
- route.tsx // Code for layout
_foo/
- index.tsx
- route.tsx // Code for layout
to have the layout in the same folder with the route

Did you find this page helpful?