Client-Side Setup
- Prerequisites
- Installation
- Customizing the App
- AI Assistants and IDE Integrations
- Manual Setup
- Configuring Defaults
- Defining a Root Element
- Content Security Policy
- HTTP Client
Once you have your server-side framework configured, you then need to set up your client-side framework. Inertia currently provides support for React, Vue, and Svelte.
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.
1npm install vue @vitejs/plugin-vue1npm install vue @vitejs/plugin-vue
1npm install react react-dom @vitejs/plugin-react1npm install react react-dom @vitejs/plugin-react
1npm install svelte @sveltejs/vite-plugin-svelte1npm install svelte @sveltejs/vite-plugin-svelte
Then, add the framework plugin to your vite.config.js file.
1import { defineConfig } from 'vite'2import laravel from 'laravel-vite-plugin'3import vue from '@vitejs/plugin-vue'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.js'],9 refresh: true,10 }),11 vue(),12 ],13})1import { defineConfig } from 'vite'2import laravel from 'laravel-vite-plugin'3import vue from '@vitejs/plugin-vue'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.js'],9 refresh: true,10 }),11 vue(),12 ],13})
1import { defineConfig } from 'vite'2import laravel from 'laravel-vite-plugin'3import react from '@vitejs/plugin-react'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.jsx'],9 refresh: true,10 }),11 react(),12 ],13})1import { defineConfig } from 'vite'2import laravel from 'laravel-vite-plugin'3import react from '@vitejs/plugin-react'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.jsx'],9 refresh: true,10 }),11 react(),12 ],13})
1import { defineConfig } from 'vite'2import laravel from 'laravel-vite-plugin'3import { svelte } from '@sveltejs/vite-plugin-svelte'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.js'],9 refresh: true,10 }),11 svelte(),12 ],13})1import { defineConfig } from 'vite'2import laravel from 'laravel-vite-plugin'3import { svelte } from '@sveltejs/vite-plugin-svelte'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.js'],9 refresh: true,10 }),11 svelte(),12 ],13})
For more information on configuring these plugins, consult Laravel's Vite documentation.
Installation
The @inertiajs/vite plugin supports Vite 7 and Vite 8.
1. Install dependencies
Install the Inertia client-side adapter and Vite plugin.
1npm install @inertiajs/vue3 @inertiajs/vite1npm install @inertiajs/vue3 @inertiajs/vite
1npm install @inertiajs/react @inertiajs/vite1npm install @inertiajs/react @inertiajs/vite
1npm install @inertiajs/svelte @inertiajs/vite1npm install @inertiajs/svelte @inertiajs/vite
2. Configure Vite
Add the Inertia plugin to your vite.config.js file.
1import inertia from '@inertiajs/vite'2import laravel from 'laravel-vite-plugin'3import { defineConfig } from 'vite'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.js'],9 refresh: true,10 }),11 inertia(),12 ],13})1import inertia from '@inertiajs/vite'2import laravel from 'laravel-vite-plugin'3import { defineConfig } from 'vite'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.js'],9 refresh: true,10 }),11 inertia(),12 ],13})
3. 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.
1import { createInertiaApp } from '@inertiajs/vue3'23createInertiaApp()1import { createInertiaApp } from '@inertiajs/vue3'23createInertiaApp()
1import { createInertiaApp } from '@inertiajs/react'23createInertiaApp()1import { createInertiaApp } from '@inertiajs/react'23createInertiaApp()
1import { createInertiaApp } from '@inertiajs/svelte'23createInertiaApp()1import { createInertiaApp } from '@inertiajs/svelte'23createInertiaApp()
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 the strictMode option.
1createInertiaApp({2 strictMode: true,3 // ...4})1createInertiaApp({2 strictMode: true,3 // ...4})
Pages Shorthand
You may use the pages shorthand to customize which directory to search for page components.
1createInertiaApp({2 pages: './AppPages',3 // ...4})1createInertiaApp({2 pages: './AppPages',3 // ...4})
1createInertiaApp({2 pages: './AppPages',3 // ...4})1createInertiaApp({2 pages: './AppPages',3 // ...4})
1createInertiaApp({2 pages: './AppPages',3 // ...4})1createInertiaApp({2 pages: './AppPages',3 // ...4})
An object may also be provided for more control over how pages are resolved. You only need to include the options you wish to customize.
1createInertiaApp({2 pages: {3 path: './Pages',4 extension: '.tsx',5 lazy: true,6 transform: (name, page) => name.replace('/', '-'),7 },8})1createInertiaApp({2 pages: {3 path: './Pages',4 extension: '.tsx',5 lazy: true,6 transform: (name, page) => name.replace('/', '-'),7 },8})
| 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. |
Customizing the App
Sometimes, you may wish to customize the app instance, for example, to register plugins, wrap it with providers, or set context values. Pass the withApp callback to createInertiaApp to customize the app before it renders.
1import { createInertiaApp } from '@inertiajs/vue3'2import { createI18n } from 'vue-i18n'34const i18n = createI18n({5 // ...6})78createInertiaApp({9 withApp(app) {10 app.use(i18n)11 },12})1import { createInertiaApp } from '@inertiajs/vue3'2import { createI18n } from 'vue-i18n'34const i18n = createI18n({5 // ...6})78createInertiaApp({9 withApp(app) {10 app.use(i18n)11 },12})
1import { createInertiaApp } from '@inertiajs/react'2import { QueryClient, QueryClientProvider } from '@tanstack/react-query'34const queryClient = new QueryClient()56createInertiaApp({7 withApp(app) {8 return (9 <QueryClientProvider client={queryClient}>10 {app}11 </QueryClientProvider>12 )13 },14})1import { createInertiaApp } from '@inertiajs/react'2import { QueryClient, QueryClientProvider } from '@tanstack/react-query'34const queryClient = new QueryClient()56createInertiaApp({7 withApp(app) {8 return (9 <QueryClientProvider client={queryClient}>10 {app}11 </QueryClientProvider>12 )13 },14})
1import { createInertiaApp } from '@inertiajs/svelte'23createInertiaApp({4 withApp(context) {5 context.set('theme', 'dark')6 },7})1import { createInertiaApp } from '@inertiajs/svelte'23createInertiaApp({4 withApp(context) {5 context.set('theme', 'dark')6 },7})
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 argument provides the current rendering environment via ssr, allowing you to conditionally apply logic based on where the app is running.
1createInertiaApp({2 withApp(app, { ssr }) {3 app.use(i18n)45 if (!ssr) {6 app.use(browserOnlyPlugin)7 }8 },9})1createInertiaApp({2 withApp(app, { ssr }) {3 app.use(i18n)45 if (!ssr) {6 app.use(browserOnlyPlugin)7 }8 },9})
1createInertiaApp({2 withApp(app, { ssr }) {3 if (!ssr) {4 return <BrowserProvider>{app}</BrowserProvider>5 }67 return app8 },9})1createInertiaApp({2 withApp(app, { ssr }) {3 if (!ssr) {4 return <BrowserProvider>{app}</BrowserProvider>5 }67 return app8 },9})
1createInertiaApp({2 withApp(context, { ssr }) {3 context.set('theme', 'dark')45 if (!ssr) {6 context.set('analytics', createAnalytics())7 }8 },9})1createInertiaApp({2 withApp(context, { ssr }) {3 context.set('theme', 'dark')45 if (!ssr) {6 context.set('analytics', createAnalytics())7 }8 },9})
The second argument also includes the current page object, giving you access to the component name, URL, version, and shared props before the app renders. This is useful for configuring plugins or providers with server-driven state, such as the user's locale.
1createInertiaApp({2 withApp(app, { page }) {3 const i18n = createI18n({ locale: page.props.locale })45 app.use(i18n)6 },7})1createInertiaApp({2 withApp(app, { page }) {3 const i18n = createI18n({ locale: page.props.locale })45 app.use(i18n)6 },7})
1createInertiaApp({2 withApp(app, { page }) {3 const i18n = createI18n({ locale: page.props.locale })45 return <I18nProvider i18n={i18n}>{app}</I18nProvider>6 },7})1createInertiaApp({2 withApp(app, { page }) {3 const i18n = createI18n({ locale: page.props.locale })45 return <I18nProvider i18n={i18n}>{app}</I18nProvider>6 },7})
1createInertiaApp({2 withApp(context, { page }) {3 context.set('locale', page.props.locale)4 },5})1createInertiaApp({2 withApp(context, { page }) {3 context.set('locale', page.props.locale)4 },5})
AI Assistants and IDE Integrations
AI assistants and IDE integrations often write state files into your project root. With laravel-vite-plugin's refresh: true enabled, these writes may trigger unexpected full page reloads, since Vite's watcher only ignores node_modules and .git by default.
You may extend Vite's server.watch.ignored option to exclude these paths.
1export default defineConfig({2 server: {3 watch: {4 ignored: [5 '**/.junie/**',6 '**/.cursor/**',7 '**/.claude/**',8 ],9 },10 },11 // ...12})1export default defineConfig({2 server: {3 watch: {4 ignored: [5 '**/.junie/**',6 '**/.cursor/**',7 '**/.claude/**',8 ],9 },10 },11 // ...12})
Adjust the list to match your installed tools. See Vite's server.watch documentation for additional options.
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.
A manual setup callback prevents the Vite plugin from auto-generating SSR handling. You should create a separate SSR entry point and update your app to use client-side hydration.
1import { createApp, h } from 'vue'2import { createInertiaApp } from '@inertiajs/vue3'34createInertiaApp({5 resolve: name => {6 const pages = import.meta.glob('./Pages/**/*.vue')7 return pages[`./Pages/${name}.vue`]()8 },9 setup({ el, App, props, plugin }) {10 createApp({ render: () => h(App, props) })11 .use(plugin)12 .mount(el)13 },14})1import { createApp, h } from 'vue'2import { createInertiaApp } from '@inertiajs/vue3'34createInertiaApp({5 resolve: name => {6 const pages = import.meta.glob('./Pages/**/*.vue')7 return pages[`./Pages/${name}.vue`]()8 },9 setup({ el, App, props, plugin }) {10 createApp({ render: () => h(App, props) })11 .use(plugin)12 .mount(el)13 },14})
1import { createInertiaApp } from '@inertiajs/react'2import { createRoot } from 'react-dom/client'34createInertiaApp({5 resolve: name => {6 const pages = import.meta.glob('./Pages/**/*.jsx')7 return pages[`./Pages/${name}.jsx`]()8 },9 setup({ el, App, props }) {10 createRoot(el).render(<App {...props} />)11 },12})1import { createInertiaApp } from '@inertiajs/react'2import { createRoot } from 'react-dom/client'34createInertiaApp({5 resolve: name => {6 const pages = import.meta.glob('./Pages/**/*.jsx')7 return pages[`./Pages/${name}.jsx`]()8 },9 setup({ el, App, props }) {10 createRoot(el).render(<App {...props} />)11 },12})
1import { createInertiaApp } from '@inertiajs/svelte'2import { mount } from 'svelte'34createInertiaApp({5 resolve: name => {6 const pages = import.meta.glob('./Pages/**/*.svelte')7 return pages[`./Pages/${name}.svelte`]()8 },9 setup({ el, App, props }) {10 mount(App, { target: el, props })11 },12})1import { createInertiaApp } from '@inertiajs/svelte'2import { mount } from 'svelte'34createInertiaApp({5 resolve: name => {6 const pages = import.meta.glob('./Pages/**/*.svelte')7 return pages[`./Pages/${name}.svelte`]()8 },9 setup({ el, App, props }) {10 mount(App, { target: el, props })11 },12})
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.
1import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'23resolve: name => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),1import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'23resolve: name => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
1import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'23resolve: name => resolvePageComponent(`./Pages/${name}.jsx`, import.meta.glob('./Pages/**/*.jsx')),1import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'23resolve: name => resolvePageComponent(`./Pages/${name}.jsx`, import.meta.glob('./Pages/**/*.jsx')),
1import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'23resolve: name => resolvePageComponent(`./Pages/${name}.svelte`, import.meta.glob('./Pages/**/*.svelte')),1import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'23resolve: name => resolvePageComponent(`./Pages/${name}.svelte`, import.meta.glob('./Pages/**/*.svelte')),
Configuring Defaults
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.
1createInertiaApp({2 defaults: {3 form: {4 recentlySuccessfulDuration: 5000,5 },6 prefetch: {7 cacheFor: "1m",8 hoverDelay: 150,9 },10 visitOptions: (href, options) => {11 return {12 headers: {13 ...options.headers,14 "X-Custom-Header": "value",15 },16 };17 },18 },19 // ...20});1createInertiaApp({2 defaults: {3 form: {4 recentlySuccessfulDuration: 5000,5 },6 prefetch: {7 cacheFor: "1m",8 hoverDelay: 150,9 },10 visitOptions: (href, options) => {11 return {12 headers: {13 ...options.headers,14 "X-Custom-Header": "value",15 },16 };17 },18 },19 // ...20});
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.
1import { config } from "@inertiajs/vue3";23// Set a single value using dot notation...4config.set("form.recentlySuccessfulDuration", 1000);5config.set("prefetch.cacheFor", "5m");67// Set multiple values at once...8config.set({9 "form.recentlySuccessfulDuration": 1000,10 "prefetch.cacheFor": "5m",11});1import { config } from "@inertiajs/vue3";23// Set a single value using dot notation...4config.set("form.recentlySuccessfulDuration", 1000);5config.set("prefetch.cacheFor", "5m");67// Set multiple values at once...8config.set({9 "form.recentlySuccessfulDuration": 1000,10 "prefetch.cacheFor": "5m",11});
1import { config } from "@inertiajs/react";23// Set a single value using dot notation...4config.set("form.recentlySuccessfulDuration", 1000);5config.set("prefetch.cacheFor", "5m");67// Set multiple values at once...8config.set({9 "form.recentlySuccessfulDuration": 1000,10 "prefetch.cacheFor": "5m",11});1213// Get a configuration value...14const duration = config.get("form.recentlySuccessfulDuration");1import { config } from "@inertiajs/react";23// Set a single value using dot notation...4config.set("form.recentlySuccessfulDuration", 1000);5config.set("prefetch.cacheFor", "5m");67// Set multiple values at once...8config.set({9 "form.recentlySuccessfulDuration": 1000,10 "prefetch.cacheFor": "5m",11});1213// Get a configuration value...14const duration = config.get("form.recentlySuccessfulDuration");
1import { config } from "@inertiajs/svelte";23// Set a single value using dot notation...4config.set("form.recentlySuccessfulDuration", 1000);5config.set("prefetch.cacheFor", "5m");67// Set multiple values at once...8config.set({9 "form.recentlySuccessfulDuration": 1000,10 "prefetch.cacheFor": "5m",11});1213// Get a configuration value...14const duration = config.get("form.recentlySuccessfulDuration");1import { config } from "@inertiajs/svelte";23// Set a single value using dot notation...4config.set("form.recentlySuccessfulDuration", 1000);5config.set("prefetch.cacheFor", "5m");67// Set multiple values at once...8config.set({9 "form.recentlySuccessfulDuration": 1000,10 "prefetch.cacheFor": "5m",11});1213// Get a configuration value...14const duration = config.get("form.recentlySuccessfulDuration");
Defining a Root Element
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.
1createInertiaApp({2 id: "my-app",3 // ...4});1createInertiaApp({2 id: "my-app",3 // ...4});
If you change the id of the root element, be sure to update it server-side as well.
Content Security Policy
For applications using a Content Security Policy that restricts inline styles, you may pass a nonce to createInertiaApp(). The nonce is applied to the inline styles Inertia injects for the progress bar and the error modal, allowing them through your CSP.
1createInertiaApp({2 nonce: "your-csp-nonce",3 // ...4});1createInertiaApp({2 nonce: "your-csp-nonce",3 // ...4});
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.
1import { axiosAdapter } from '@inertiajs/core'23createInertiaApp({4 http: axiosAdapter(),5 // ...6})1import { axiosAdapter } from '@inertiajs/core'23createInertiaApp({4 http: axiosAdapter(),5 // ...6})
A custom Axios instance may also be provided to the adapter.
1import axios from 'axios'2import { axiosAdapter } from '@inertiajs/core'34const instance = axios.create({5 // ...6})78createInertiaApp({9 http: axiosAdapter(instance),10 // ...11})1import axios from 'axios'2import { axiosAdapter } from '@inertiajs/core'34const instance = axios.create({5 // ...6})78createInertiaApp({9 http: axiosAdapter(instance),10 // ...11})
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.
1import { http } from '@inertiajs/vue3'23const removeRequestHandler = http.onRequest((config) => {4 config.headers['X-Custom-Header'] = 'value'5 return config6})78const removeResponseHandler = http.onResponse((response) => {9 console.log('Response status:', response.status)10 return response11})1213const removeErrorHandler = http.onError((error) => {14 console.error('Request failed:', error)15})1617// Remove a handler when it's no longer needed...18removeRequestHandler()1import { http } from '@inertiajs/vue3'23const removeRequestHandler = http.onRequest((config) => {4 config.headers['X-Custom-Header'] = 'value'5 return config6})78const removeResponseHandler = http.onResponse((response) => {9 console.log('Response status:', response.status)10 return response11})1213const removeErrorHandler = http.onError((error) => {14 console.error('Request failed:', error)15})1617// Remove a handler when it's no longer needed...18removeRequestHandler()
1import { http } from '@inertiajs/react'23const removeRequestHandler = http.onRequest((config) => {4 config.headers['X-Custom-Header'] = 'value'5 return config6})78const removeResponseHandler = http.onResponse((response) => {9 console.log('Response status:', response.status)10 return response11})1213const removeErrorHandler = http.onError((error) => {14 console.error('Request failed:', error)15})1617// Remove a handler when it's no longer needed...18removeRequestHandler()1import { http } from '@inertiajs/react'23const removeRequestHandler = http.onRequest((config) => {4 config.headers['X-Custom-Header'] = 'value'5 return config6})78const removeResponseHandler = http.onResponse((response) => {9 console.log('Response status:', response.status)10 return response11})1213const removeErrorHandler = http.onError((error) => {14 console.error('Request failed:', error)15})1617// Remove a handler when it's no longer needed...18removeRequestHandler()
1import { http } from '@inertiajs/svelte'23const removeRequestHandler = http.onRequest((config) => {4 config.headers['X-Custom-Header'] = 'value'5 return config6})78const removeResponseHandler = http.onResponse((response) => {9 console.log('Response status:', response.status)10 return response11})1213const removeErrorHandler = http.onError((error) => {14 console.error('Request failed:', error)15})1617// Remove a handler when it's no longer needed...18removeRequestHandler()1import { http } from '@inertiajs/svelte'23const removeRequestHandler = http.onRequest((config) => {4 config.headers['X-Custom-Header'] = 'value'5 return config6})78const removeResponseHandler = http.onResponse((response) => {9 console.log('Response status:', response.status)10 return response11})1213const removeErrorHandler = http.onError((error) => {14 console.error('Request failed:', error)15})1617// Remove a handler when it's no longer needed...18removeRequestHandler()
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.