Next.js Discord

Discord Forum

app router templates

Answered
Basque Shepherd Dog posted this in #help-forum
Open in Discord
Basque Shepherd DogOP
How do I define a template so that the index page has custom layout, but every other page uses a separate layout?
example:

/    - use layout X
/foo - use layout Y
/bar - use layout Y
/baz - use layout Y
/... - use layout Y
Answered by Russian Blue
you can group pages by using () in the naming as such:

(layout-1-pages) and place a layout in it, and all other pages place in (layout-2-pages) and a corresponding layout in it
View full answer

17 Replies

Basque Shepherd DogOP
yes. I read that. but I didnt figure it out
@Finnish Spitz
Finnish Spitz
what didnt you understand?
Basque Shepherd DogOP
how can I use a layout for all pages except the index page?
Basque Shepherd DogOP
@Finnish Spitz sorry for ping
Russian Blue
you can group pages by using () in the naming as such:

(layout-1-pages) and place a layout in it, and all other pages place in (layout-2-pages) and a corresponding layout in it
Answer
Basque Shepherd DogOP
@Russian Blue so can I do something like this?
app/
L (custom)
   L page.tsx
   L layout.tsx (layout X)
L layout.tsx (layout Y)
L foo/page.tsx
L bar/page.tsx
L baz/page.tsx

will this result in foo, bar, and baz using layout Y, and the root index page using layout X?
or do these also need to be in a group
foo bar baz will use layout Y
however root index will use layout X AND Y
this setup has one root layout
if you need 2 root layout then you'd need to make two route groups at the root-level
Basque Shepherd DogOP
ahh you're right I see that
so I will need 2 separate groups since I want the layouts to be completely different
thank you guys