Jin
Jin

Reputation: 31

An error occurs in ZiggyVue.(Cannot find name 'route')

When developing with laravel9 and typescript, I get a ZiggyVue error when using "route".

There is no problem with the operation.

How can I resolve this error?

Error Message

Cannot find name 'route' ts(2304)

Version

app.ts

import './bootstrap';
import '../css/app.css';

import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';

const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({ el, app, props, plugin }) {
        return createApp({ render: () => h(app, props) })
            .use(plugin)
            .use(ZiggyVue, Ziggy)
            .mount(el);
    },
});

InertiaProgress.init({
  includeCSS: true,
  showSpinner: true,
});

Upvotes: 3

Views: 1407

Answers (2)

Mclean Kasambala
Mclean Kasambala

Reputation: 56

I know this post is old. But I thought this might help someone. Define the following declaration:

declare function route(name:string, params?: any);

Source: enter link description here

Upvotes: 0

Dávid Michalco
Dávid Michalco

Reputation: 27

Try adding

import { Ziggy } from './ziggy';

to your app.js.

And mabye try to use this.route() instead of just route.

Upvotes: 0

Related Questions