Pages usually share a common visual design. The +Layout setting enables you to define such shared visual appearance.
You can also define multiple designs: some pages can share a design while other pages share another one. (For example, admin pages and marketing pages typically have a different design.)
The component defined by the +Layout setting wraps the component defined by +Page.
<Layout> ⟸ component defined by +Layout <Page /> ⟸ component defined by +Page</Layout>
If you want to add a wrapper component that is required for installing a tool, then we generally recommend using <Wrapper> instead.
Global
You can define a layout that applies to all your pages:
# Global outer layout that applies to all pagespages/+Layout.js# Inner layout nested into the global outer layout, for marketing pagespages/(marketing)/+Layout.js# Inner layout nested into the global outer layout, for admin pagespages/admin-panel/+Layout.js
Here pages/+Layout.js applies to all pages, including the marketing and admin pages.
The Layout setting is cumulative: pages/(marketing)/+Layout.js doesn't override pages/+Layout.js. Instead, the <Layout> components nest within each other:
pages/+Layout.js # Global layout (shared among all pages)pages/product/@id/+Layout.js # Outer content ("Macbook" ...)pages/product/@id/pricing/+Page.js # Inner content ("Pricing" ...)pages/product/@id/reviews/+Page.js # Inner content ("Reviews" ...)
If your nested layout isn't associated with a URL (if the pricing and reviews tabs share the same URL /product/42) then you can use a stateful component instead of <Layout>.
To avoid the page scrolling to the top, make sure to use:
See the Nested section above. For smooth nested layout navigation, we recommend using Client Routing. (Using Server Routing leads to full page reloads which usually isn't acceptable for same-page navigations.)