Laravel Starter Kits
Laravel’s starter kits provide out-of-the-box scaffolding for new Inertia applications.These starter kits are the absolute fastest way to start building a new Inertia project using Laravel and Vue or React. However, if you would like to manually install Inertia into your application, please consult the documentation below.
Prerequisites
Inertia requires your client-side framework and its corresponding Vite plugin to be installed and configured. You may skip this section if your application already has these set up.vite.config.js file.
Installation
Initialize the Inertia app
Update your main JavaScript file to boot your Inertia app. The Vite plugin handles page resolution and mounting automatically, so a minimal entry point is all you need.The plugin generates a default resolver that looks for pages in both
./pages and ./Pages directories, and the app mounts automatically.React Strict Mode
The React adapter supports enabling React’s Strict Mode via thestrictMode option.
Pages Shorthand
You may use thepages shorthand to customize which directory to search for page components.
| Option | Description |
|---|---|
path | The directory to search for page components. |
extension | A string or array of file extensions (e.g., '.tsx' or ['.tsx', '.jsx']). Defaults to your framework’s extension. |
lazy | Whether to lazy-load page components. Defaults to true. See code splitting. |
transform | A callback that receives the page name and page object, returning a transformed name. |
Manual Setup
If you prefer not to use the Vite plugin, you may provide theresolve and setup callbacks manually. The resolve callback tells Inertia how to load a page component and receives the component name and the full page object. The setup callback initializes the client-side framework.
laravel-vite-plugin package also provides a resolvePageComponent helper that may be used to resolve page components.
Configuring Defaults
You may pass adefaults object to createInertiaApp() to configure default settings for various features. You don’t have to pass a default for every key, just the ones you want to tweak.
visitOptions callback receives the target URL and the current visit options, and should return an object with any options you want to override. For more details on the available configuration options, see the forms, prefetching, and manual visits documentation.
Updating Configuration at Runtime
You may also update configuration values at runtime using the exportedconfig instance. This is particularly useful when you need to adjust settings based on user preferences or application state.
Defining a Root Element
By default, Inertia assumes that your application’s root template has a root element with anid of app. If your application’s root element has a different id, you can provide it using the id property.
id of the root element, be sure to update it server-side as well.
HTTP Client
Unlike Inertia 2 and earlier, Inertia 3 uses a built-in XHR client for all requests. No additional HTTP libraries like Axios are required.Using Axios
You may provide theaxiosAdapter as the http option when creating your Inertia app. This is useful when your application requires a custom Axios instance.
Interceptors
The built-in XHR client supports interceptors for modifying requests, inspecting responses, or handling errors. These interceptors apply to all HTTP requests made by Inertia, including those from the router,useForm, <Form>, and useHttp.
on* method returns a cleanup function that removes the handler when called. Request handlers receive the request config and must return it (modified or not). Response handlers receive the response and must also return it. Handlers may be asynchronous.
Custom HTTP Client
For full control over how requests are made, you may provide a completely custom HTTP client via thehttp option. A custom client must implement the request method, which receives an HttpRequestConfig and returns a promise resolving to an HttpResponse. Review the xhrHttpClient.ts source for a reference implementation.