What is Inertia.js?
Inertia.js is a protocol that bridges your server-side framework with a client-side SPA framework. Instead of building a separate API:- Server returns page components with their props
- Client renders React components using those props
- Navigation happens via XHR, updating the page without full reloads
Architecture
Project Structure
A Kit application with Inertia has the following structure:How It Works
1. Initial Page Load
When a user visits your app for the first time:- Browser requests
/ - Kit controller returns an HTML document containing:
- The Inertia page data as JSON in the root element
- Links to your compiled React app
- React boots and renders the initial page component
2. Subsequent Navigation
When clicking links or submitting forms:- Inertia intercepts the navigation
- Makes an XHR request with
X-Inertia: trueheader - Kit returns JSON with the new page component and props
- Inertia swaps the component without a full page reload
Getting Started
Create a New Project
Start Development Server
Your First Inertia Response
In a controller, return an Inertia response:frontend/src/pages/Home.tsx:
Development vs Production
Development Mode
In development, Kit:- Serves React assets through Vite’s dev server (
http://localhost:5173) - Enables hot module replacement for instant updates
- Provides detailed error messages
Production Mode
For production, build and serve optimized assets:Key Benefits
| Feature | Benefit |
|---|---|
| No API needed | Controllers return props directly |
| Type safety | Generate TypeScript types from Rust |
| Server-side routing | Define routes once in Rust |
| SPA experience | No full page reloads |
| SEO friendly | Initial HTML is server-rendered |
| Shared validation | Use same validation rules everywhere |
Next Steps
- Inertia Responses - Learn about the
inertia_response!macro - Page Components - Create React page components
- TypeScript Types - Generate types from Rust structs