Once you have your server-side framework configured, you then need to setup your client-side framework. Inertia currently provides support for React, Vue, and Svelte.
Scaffold with create-inertiacore
InertiaCore maintains a scaffolder that wires up AspNetCore.InertiaCore, Vite, and your frontend framework of choice (Vue, React, or Svelte) in one step:
Terminal window
npminitinertiacore@latest
# or
npxcreate-inertiacore@latest
This is the fastest way to start a new InertiaCore project. If you’d prefer to add InertiaCore to an existing app, follow the manual steps 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.
Terminal window
npminstallvue@vitejs/plugin-vue
Terminal window
npminstallreactreact-dom@vitejs/plugin-react
Terminal window
npminstallsvelte@sveltejs/vite-plugin-svelte
Then, add the framework plugin to your vite.config.js file.
For more information on configuring these plugins, consult Laravel’s Vite documentation.
Installation
The @inertiajs/vite plugin supports Vite 7 and Vite 8.
Install dependencies
Install the Inertia client-side adapter and Vite plugin.
Terminal window
npminstall@inertiajs/vue3@inertiajs/vite
Terminal window
npminstall@inertiajs/react@inertiajs/vite
Terminal window
npminstall@inertiajs/svelte@inertiajs/vite
Configure Vite
Add the Inertia plugin to your vite.config.js file.
import inertia from'@inertiajs/vite'
import laravel from'laravel-vite-plugin'
import { defineConfig } from'vite'
exportdefaultdefineConfig({
plugins: [
laravel({
input: ['resources/js/app.js'],
refresh: true,
}),
inertia(),
],
})
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.
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.
Customizing the App
Sometimes you may wish to customize the app instance, for example to register plugins, wrap with providers, or set context values. Pass the withApp callback to createInertiaApp to hook into the app before it renders.
The callback receives the Vue app instance, allowing you to call app.use(), app.provide(), app.component(), and any other app-level method.
The callback receives the React element and must return a new element. This is where you may wrap your app with context providers.
The callback receives a Map that serves as Svelte’s component context. Values set here are accessible in your components via getContext().
A second { ssr } argument is also available, allowing you to conditionally apply logic based on the rendering environment.
createInertiaApp({
withApp(app, { ssr }) {
app.use(i18n)
if (!ssr) {
app.use(browserOnlyPlugin)
}
},
})
createInertiaApp({
withApp(app, { ssr }) {
if (!ssr) {
return <BrowserProvider>{app}</BrowserProvider>
}
return app
},
})
createInertiaApp({
withApp(context, { ssr }) {
context.set('theme', 'dark')
if (!ssr) {
context.set('analytics', createAnalytics())
}
},
})
Manual Setup
If you prefer not to use the Vite plugin, you may provide the resolve 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.
By default, page components are lazy-loaded, splitting each page into its own bundle. To eagerly bundle all pages into a single file instead, see the code splitting documentation.
The laravel-vite-plugin package also provides a resolvePageComponent helper that may be used to resolve page components.
You may pass a defaults 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.
createInertiaApp({
defaults: {
form: {
recentlySuccessfulDuration: 5000,
},
prefetch: {
cacheFor: "1m",
hoverDelay: 150,
},
visitOptions: (href, options) => {
return {
headers: {
...options.headers,
"X-Custom-Header": "value",
},
};
},
},
// ...
});
The 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 exported config instance. This is particularly useful when you need to adjust settings based on user preferences or application state.
By default, Inertia assumes that your application’s root template has a root element with an id of app. If your application’s root element has a different id, you can provide it using the id property.
createInertiaApp({
id: "my-app",
// ...
});
If you change the 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 the axiosAdapter as the http option when creating your Inertia app. This is useful when your application requires a custom Axios instance.
import { axiosAdapter } from'@inertiajs/core'
createInertiaApp({
http: axiosAdapter(),
// ...
})
A custom Axios instance may also be provided to the adapter.
import axios from'axios'
import { axiosAdapter } from'@inertiajs/core'
constinstance= axios.create({
// ...
})
createInertiaApp({
http: axiosAdapter(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.
Each 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 the http 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.