Your pages will usually share a common visual design.
Some pages may share a design while other pages share another design. (For example, two admin pages /admin/product/@id and /admin/user/@id sharing the same navigation sidebar, and two marketing pages / and /about-us not having any sidebar but sharing a sticky header instead.)
The Layout setting enables you to define such shared visual appearance.
The component defined by the Layout setting wraps the <Page> component.
<Layout> ⟸ component defined by the setting "Layout" <Page /> ⟸ component defined by the setting "Page"</Layout>
For integrating tools, we generally recommend using <Wrapper> instead.
Global
You can define a layout that applies to all your pages:
// /pages/+Layout.jsxexport { Layout }// children includes <Page/>function Layout({ children }) { return <> <Navigation/> <Content>{children}</Content> </>}function Navigation() { /* ... */ }function Content() { /* ... */ }
# 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.)