question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using @routes results in: Uncaught ReferenceError: Ziggy is not defined

See original GitHub issue

Currently installed Laravel version:

5.6.39

Currently installed Ziggy version

0.6.9

I’ve included the @routes directive in the header of my template.

Here is the output in the header.

<script type="text/javascript">
    (function() {
var routes = {"api.mailgun.cases.test":{"uri":"api\/mailgun\/cases\/test","methods":["GET","HEAD"],"domain":null}};

        for (var name in routes) {
            Ziggy.namedRoutes[name] = routes[name];
        }
    })();
</script>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
robfranckencommented, Apr 4, 2020

import route from 'ziggy' only imports the helper function.

If you’ve generated the routes file with the artisan command, e.g. php artisan ziggy:generate "resources/js/ziggy", you’ll need to import that file as well.

To use the route helper function, you need to make the generated routes accessible. I’ve just bound to the window object below, but you can import it into your Vue components as described in the docs if you prefer.

// resources/js/app.js

import route from 'ziggy'
import { Ziggy } from './ziggy'

window.Ziggy = Ziggy;

console.log('route', route);
console.log('Ziggy', Ziggy);
console.log('test', route('blog.index'));

Hopefully that clears things up for you!

0reactions
notflipcommented, Apr 10, 2020

Perfect! That solves it for me, thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: route is not defined · Issue #265 · tighten/ziggy
I have an issue with Ziggy, I was using it first with the directive @routes but after switching to the artisan method the...
Read more >
Laravel - Ziggy Err: $route is not a function - Stack Overflow
I would like to use the ziggy library to build routes. And my error in browser console: Uncaught (in promise) TypeError: _ctx.$route is...
Read more >
Ziggy, InertiaJS & Vite : route is not defined - Laracasts
Everything works fine on my Vue templates, but I got this js error (Uncaught ReferenceError: route is not defined) when I use the...
Read more >
Asset Bundling (Vite) - The PHP Framework For Web Artisans
Watching the routes/** directory is useful if you are utilizing Ziggy to generate route links within your application's frontend. If these default paths...
Read more >
a package providing Laravel Named Routes in JavaScript
One thing we've come back to a few times is the desire to use the Laravel route() helper with named routes in JavaScript....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found