Creating Pages
Inertia pages are simply JavaScript components. If you have ever written a Vue, React, or Svelte component, you will feel right at home. As you can see in the example below, pages receive data from your application’s controllers as props.inertia.ensure_pages_exist configuration option to true. The Laravel adapter will then throw an Inertia\ComponentNotFoundException when a page cannot be found.
Creating Layouts
While not required, for most projects it makes sense to create a layout component that all of your pages can use. You may have noticed in our page example above that we’re wrapping the page content within a<Layout> component. Here’s an example of such a component:
Persistent Layouts
While it’s simple to implement layouts as children of page components, it forces the layout instance to be destroyed and recreated between visits. This means you cannot have persistent layout state when navigating between pages. For example, maybe you have an audio player on a podcast website that you want to continue playing as users navigate the site. Or, maybe you simply want to maintain the scroll position in your sidebar navigation between page visits. In these situations, the solution is to leverage Inertia’s persistent layouts.Default Layouts
If you’re using persistent layouts, you may find it convenient to define the default page layout in theresolve() callback of your application’s main JavaScript file.
Layout if a layout has not already been set for that page.
You can even go a step further and conditionally set the default page layout based on the page name, which is available to the resolve() callback. For example, maybe you don’t want the default layout to be applied to your public pages.