So I'm making a website using Vue 3 (Composition API), InertiaJS, Laravel. As such, Ziggy is being used to allow Vue to access the Laravel routes. artisan ziggy:generate is used to create the routes file
So far, using route('my.named.route') in the <template> area works perfectly.
However, when I try to use route in the <script setup> area, even inside a function, I get route is not a function
I have a feeling this is something to do with the setup flag and whatnot, but I'm honestly not sure exactly what the cause is nor how to solve it. I've not been able to find anything in searches about it either, every search comes up with people who can't get Ziggy working at all, which is not my issue.
My app.js file looks like:
import {createApp, h} from "vue";
import {createInertiaApp, Head, Link} from "@inertiajs/vue3";
import {resolvePageComponent} from "laravel-vite-plugin/inertia-helpers";
import {Ziggy} from './ziggy';
import {ZiggyVue} from "ziggy-js/dist/vue.es";
import GeneralLayout from "./template/Layout.vue";
import DashboardLayout from "./template/DashboardLayout.vue";
import FontAwesomeIcon from "./fontawesome";
import './bootstrap';
createInertiaApp({
resolve: async (name) => {
let page = await resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue'));
if (page.default.layout === undefined) {
if (name.startsWith('Admin/')) {
page.default.layout = (h, page) => h(DashboardLayout, () => page);
} else if (name.startsWith('Business')) {
page.default.layout = (h, page) => h(GeneralLayout, () => page);
} else {
page.default.layout = (h, page) => h(GeneralLayout, () => page);
}
}
return page;
},
setup({el, App, props, plugin}) {
const app = createApp({render: () => h(App, props)})
.use(plugin)
.use(ZiggyVue, Ziggy)
.component("Link", Link)
.component("Head", Head)
.component("font-awesome-icon", FontAwesomeIcon);
app.mount(el)
},
title: title => `MySite - ${title}`,
});
My main view looks like:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,500;0,600;0,700;1,500;1,600;1,700&display=swap"
rel="stylesheet">
@inertiaHead
@vite(['resources/css/app.css', 'resources/js/app.js'])
@env('local')
{{-- Adds a toolbar at the bottom of the page summarising clockwork data --}}
<script src="https://cdn.jsdelivr.net/gh/underground-works/clockwork-browser@1/dist/toolbar.js"></script>
{{-- Provides client-side metrics to clockwork --}}
<script src="https://cdn.jsdelivr.net/gh/underground-works/clockwork-browser@1/dist/metrics.js"></script>
@endenv
</head>
<body class="antialiased">
@inertia
</body>
</html>
Thanks in advance for any assistance, and let me know if any more information is needed :)