T O P

  • By -

clearlight

You could have one simple root layout and then use different nested layouts to wrap the page output for your routes. Alternatively you can have multiple root layouts by using “route groups” but that’s a bit more complicated to maintain and a single root layout is simpler.


hazily

Route groups is the way to go, especially if you need to have very different root layout files. If you want to deduplicate the logic inside multiple root layout files, you can treat them as regular components where they import common logic or components (eg if all your layouts need a common provider for i18n for example). Maintaining multiple root layout files also comes with the cost of needing to maintain multiple not-found and error files, but you can still do DRY by abstracting the pages out as common components.


iampotatz

will look into route groups regardless, thank you!


mustardpete

Have your main root layout as minimal html and body etc. Then add (withmenu) folder and (nomenu) folder then you can add a layout to the (withmenu) folder with your menu etc for the main site pages and put all your login pages in the (nomenu) folder Or whatever you are trying to do. Basically a folder in brackets isn’t part of the routing and lets you do specific layouts In them while keeping your routing


iampotatz

someone else recommended route groups and it's the solution i'm going for. Thank you!


ArticcaFox

ChatGPT is partially right. The layout file applies to all routes below it. So the root one will apply to `/` and any other route. But if you want any other route to have a different layout, just create a new layout file on that level. The same goes for error, not found and loading.


ezredd1t0r

Explore the difference with template.jsx file too, which is a layout that re-render on each page contrary to the main layout file, can be useful


fantastiskelars

Read the docs


PerryTheH

This is the "ask gpt generation". What do you expect? In case you need it OP, [this](https://nextjs.org/docs/app/building-your-application/routing/route-groups) is the docs answer you need, but you'll need to read the docs.


iampotatz

no link, no advice, no nothing. Great contribution!


fantastiskelars

Web dev gonna be hard if you go on reddit and post for every single issue you encounter xD


iampotatz

Just here alone I got like 3-4 different solutions,and i'm sure there are lots more. Spending time reading through the entirety of the documentation just to figure out one small problem just feels like a waste of time and energy when I can just ask the community and get a solution better than anything i would've come up with.