I try use stack Laravel + Inertiajs + Vue3. I would like to use the ziggy library to build routes.
And my error in browser console:
Uncaught (in promise) TypeError: _ctx.$route is not a function
- Laravel successful
- Inertiajs successful
- Vue3 successful
Next i install Ziggy
composer require tightenco/ziggy.
my app.js
require('./bootstrap');
import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/inertia-vue3'
import { InertiaProgress } from '@inertiajs/progress'
import { ZiggyVue } from 'ziggy';
InertiaProgress.init()
createInertiaApp({
resolve: name => require(`./Pages/${name}`),
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin, ZiggyVue)
.mount(el)
},
})
console.log(route('test'))
my webpack.mix.js
const mix = require('laravel-mix');
const path = require('path');
mix.alias({
ziggy: path.resolve('vendor/tightenco/ziggy/dist/vue'),
});
mix.js('resources/js/app.js', 'public/js').vue()
.postCss('resources/css/app.css', 'public/css', [
require('tailwindcss'),
]);
my root blade:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<link href="{{ mix('/css/app.css') }}" rel="stylesheet" />
@routes
<script src="{{ mix('/js/app.js') }}" defer></script>
@inertiaHead
</head>
<body>
@inertia
</body>
</html>
my vue page Pages/Home.vue
<template>
<Head title="Welcome" />
<h1 class="text-9xl">Welcome</h1>
<p>Hello, welcome to your first Inertia app!</p>
<br>
<InertiaLink :href="$route('test')">Test</InertiaLink>
</template>
<script>
import { Head } from '@inertiajs/inertia-vue3'
export default {
components: {
Head,
},
}
</script>
I will be grateful for help
In app.js-