Use Inertia.js to render Vue or React pages from Laravel controllers without a separate API.
Inertia.js — SPA without API
composer require inertiajs/inertia-laravel
npm install @inertiajs/vue3
// Route returns Inertia response
Route::get("/dashboard", function () {
return Inertia::render("Dashboard", [
"user" => auth()->user(),
"posts" => PostResource::collection(Post::latest()->take(5)->get()),
]);
});
// Vue component (resources/js/Pages/Dashboard.vue)
<script setup>
import { usePage } from "@inertiajs/vue3";
const { user, posts } = usePage().props;
</script>
<template>
<div>
<h1>Welcome, {{ user.name }}</h1>
<PostList :posts="posts" />
</div>
</template>
// Form submission
import { useForm } from "@inertiajs/vue3";
const form = useForm({ title: "", body: "" });
form.post("/posts", { onSuccess: () => form.reset() });