Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

panthro's avatar

Ziggy - using routes inside a component

I've set up Ziggy and it is working, but when I want to use it inside a components setup, I get the error:

route is not defined.

If I use route inside of the template I do not get this error.

How can I fix it?

0 likes
2 replies
tykus's avatar

In the app.js file where you create the Inertia app, you can mixin the route function from the window Object:

let app = createInertiaApp({
  resolve: name => {
    // ...
  },
  setup({el, App, props, plugin}) {
    createApp({render: () => h(App, props)})
      .use(plugin)
      .mixin({methods: {route: window.route}})
      .mount(el)
// ...

Now, it should be available to your Vue components.

panthro's avatar

@tykus thanks, same issue though, route is not defined in the component.

Please or to participate in this conversation.