Creating Layouts
A layout is a standard component that accepts child content. There is nothing Inertia-specific about it.Persistent Layouts
Wrapping a page with a layout as a child component works, but it means the layout is destroyed and recreated on every visit. This prevents maintaining layout state across navigations, such as an audio player that should keep playing or a sidebar that should retain its scroll position. Persistent layouts solve this by telling Inertia which layout to use for a page. Inertia then manages the layout instance separately, keeping it alive between visits.Nested Layouts
You may create more complex layout arrangements using nested layouts. Pass an array of layout components to wrap the page in multiple layers.Default Layouts
Thelayout option in createInertiaApp lets you define a default layout for all pages, saving you from defining it on every page individually. Per-page layouts always take precedence over the default.
layout callback supports all layout formats, including arrays for nested layouts, named objects for named layouts, and tuples for static props.
Using the Resolve Callback
You may also set a default layout inside theresolve callback by mutating the resolved page component. The callback receives the component name and the full page object, which is useful when you need to conditionally apply layouts based on page data.
Layout Props
Persistent layouts often need dynamic data from the current page, such as a page title, the active navigation item, or a sidebar toggle. Layout props provide a way to define defaults in your layout and override them from any page.Defining Defaults
Use theuseLayoutProps hook in your layout component to declare which props the layout accepts and their default values.
Setting Props From Pages
Use thesetLayoutProps function from any page component to update the layout’s props dynamically.
{ title: 'Dashboard', showSidebar: false }.
Targeting Named Layouts
You may also define your persistent layouts as a named object, allowing you to target specific layouts with props.setLayoutPropsFor to set props for a specific named layout.
Static Props
You may also pass static props directly in your persistent layout definition using a tuple. Static props are set once when the layout is defined and don’t change between page navigations.Merge Priority
Layout props are resolved from three sources with the following priority (highest to lowest):- Dynamic props - set via
setLayoutProps()orsetLayoutPropsFor() - Static props - defined in the persistent layout definition
- Defaults - declared in
useLayoutProps()
Auto-Reset on Navigation
Dynamic layout props are automatically reset to their defaults when navigating to a new page (unlesspreserveState is enabled). This ensures each page starts with a clean slate and only the layout props explicitly set by that page are applied.
Resetting Props
You may also manually reset all dynamic layout props back to their defaults usingresetLayoutProps.