Skip to main content
Sometimes you need to access specific pieces of data on numerous pages within your application. For example, you may need to display the current user in the site header. Passing this data manually in each response across your entire application is cumbersome. Thankfully, there is a better option: shared data.

Sharing Data

All of Inertia’s server-side adapters provide a method to make shared data available for every request. This is typically done outside of your controllers. Shared data is automatically merged with the page props provided in your controller. In Laravel applications, this is typically handled by the HandleInertiaRequests middlewarethe Share function on inertia.Middlewarethe HandleInertiaRequests middleware configured during server-side setup.
Shared data should be used sparingly as all shared data is included with every response. Page props and shared data are merged together, so be sure to namespace your shared data appropriately to avoid collisions.

Sharing Once Props

You may share data that is resolved only once and remembered by the client across subsequent navigations using once props.

Accessing Shared Data

Once you have shared the data server-side, you will be able to access it within any of your pages or components. Here’s an example of how to access shared data in a layout component.

TypeScript

You may configure the shared props type globally using TypeScript’s declaration merging.

Flash Data

For one-time notifications like toast messages or success alerts, you may use flash data. Unlike shared data, flash data is not persisted in the browser’s history state, so it won’t reappear when navigating through history.