The Modern Monolith. Build single-page apps without building an API. Seamlessly connect your React/Vue/Svelte frontend with your CanxJS backend.
Build SPAs using classic server-side routing and controllers.
Pass data directly to components. No REST/GraphQL needed.
Share data like Auth logic automatically across all pages.
Automatic reload when assets change.
Configure the root view and shared data in your app config.
1// src/config/app.ts2export const config = {3// ...4inertia: {5rootView: 'app', // views/app.tsx or views/app.ejs6shared: (req) => ({7auth: {8user: req.user,9},10flash: {11success: req.session.get('success'),12error: req.session.get('error'),13}14}),15}16};
Return Inertia.render from your controllers.
1// src/controllers/DashboardController.ts2import { Controller } from "canxjs/controller";3import { Inertia } from "canxjs";45export class DashboardController extends Controller {6@Get("/")7async index() {8// Render the "Dashboard" component with props9return Inertia.render("Dashboard", {10stats: {11users: 100,12revenue: 500013}14});15}16}
Initialize the Inertia app in your frontend entry point.
1// resources/js/app.tsx (React)2import { createInertiaApp } from '@inertiajs/react';3import { createRoot } from 'react-dom/client';45createInertiaApp({6resolve: name => {7const pages = import.meta.glob('./Pages/**/*.tsx', { eager: true });8return pages[`./Pages/${name}.tsx`];9},10setup({ el, App, props }) {11createRoot(el).render(<App {...props} />);12},13});