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
Layout props are defined as regular component props with default values.Static Props
You may pass static props directly in your persistent layout definition using a tuple. These props are set once when the layout is defined and don’t change between page navigations.Callback Props
Sometimes layout props need to be derived from the current page’s props. A callback function receives the page props and returns a layout definition with computed static props.LayoutCallback type for type safety.
Returning Props Only
When a default layout is configured increateInertiaApp, callbacks may return a plain props object instead of a full layout definition. Inertia will automatically use the default layout and merge the returned props onto it.
Dynamic Props
You may also update layout props dynamically from any page component using thesetLayoutProps function. TypeScript users may type these props globally.
Targeting Named Layouts
Nested layouts may also be defined as a named object instead of an array, allowing you to target specific layouts with props.setLayoutProps.
Merge Priority
Layout props are resolved from multiple sources with the following priority (highest to lowest):- Dynamic props - set via
setLayoutProps() - Static props - defined in the persistent layout definition (including callback props)
- Defaults - declared as default values on the layout component’s props
Auto-Reset on Navigation
Dynamic layout props are automatically reset 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 usingresetLayoutProps.