No API routes necessary, that's the beauty of Inertia.
Route::get('/', function () {
// Laravel way
// return view('welcome', [
// 'name' => 'Andre',
// ]);
// Inertia way
return Inertia::render('Welcome', [
'name' => 'Andre',
]);
});
Now, name should be available as a prop in your Welcome.vue page component. Depending on which version of Vue you're using, you can accept the prop and use it anywhere in that component. Here's an example with Vue 3 and script setup.
<script setup>
defineProps({
name: String,
})
</script>
<template>
<div>Hello, {{ name }}</div>
</template>
Be sure to checkout the Inertia series here on Laracasts: https://laracasts.com/series/build-modern-laravel-apps-using-inertia-js/episodes/1
As well as the official demo app so you can play around with it: https://inertiajs.com/demo-application