Next.js Discord

Discord Forum

Can you completely override the root layout? (is there ever a good reason to?)

Answered
Jumbo flying squid posted this in #help-forum
Open in Discord
Jumbo flying squidOP
So i see the root layout is required to have html/body tags.
Lets say in the /manager/blog route, i want to change some things at the root level so i want to have a new html/body on the page. is that possible? I dont know why i'd need such a thing, but i was curious, if we can only place things inside the root layout, or can we ever override it and start fresh in a deeper route?
Answered by luis_llanes
Yes it's definitely possible. Just have in mind that if you navigate from one of the root layouts to the other you will get a full page load since you're essentially re-mounting the whole HTML structure.

I like to think about multiple root layouts as different apps within the same app lol
View full answer

10 Replies

Jumbo flying squidOP
Cool thanks for that link.
Looks like you can't 'override' the root layout, but can omit it and allow the other folder's layout files become the main one then.
You mean override as displaying a different layout and distribution visually?
You can have nested layouts, and those can vary between each others

Say you have a rootLayout in /app/layout.tsx

This RootLayout will have the <html> <body> tags and all the basic & common configuration across your whole app.

Maybe import the global css, your fonts, your global metadata, and instead of providing a layout (as in HTML elements defining the structure and styles of your pages) just directly render <body>{children}</body> and override the layout on each nested layouts

Idk if it makes sense?
Most of the times you don’t want to create whole new root layout (with the <html> and <body> tags) for different groups of routes, you just need a nested layout that defines the structure and styles from there down
@luis_llanes Most of the times you don’t want to create whole new *root layout* (with the <html> and <body> tags) for different groups of routes, you just need a nested layout that defines the structure and styles from there down
Jumbo flying squidOP
yes, i kinda figured most the time that would be optimal, just curious if can get fully changed (which seems possible if omit the root layout).
Thanks for your help as well @luis_llanes !
Answer