ReferenceError: route is not defined
See original GitHub issueI have an issue with Ziggy, I was using it first with the directive @routes
but after switching to the artisan method the route
helper function fails to import,
###Steps to reproduce
in webpack.mix:
ziggy: path.resolve(
__dirname,
'vendor/tightenco/ziggy/dist/js/route.js'),
ziggyRoutes: path.resolve(
__dirname,
'resources/assets/js/ziggy.js'),
in app.js:
import route from 'ziggy';
import { Ziggy } from 'ziggyRoutes'
Vue.mixin({
methods: {
route: (name, params, absolute) => window._route(name, params, absolute, Ziggy),
}
});
Current Behavior
[Vue warn]: Error in data(): “ReferenceError: route is not defined”
For bug reports only please provide
Currently installed Laravel version:
5.7
Currently installed Ziggy version
v0.6.8.1
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Node 101: app.use ReferenceError [route] not defined
Make sure you require your edu module in your app.js file. Usually at the top of the file you would need something like...
Read more >Uncaught ReferenceError: route is not defined · Issue #482
This message disappears once a user is logged in. Uncaught ReferenceError: route is not defined at Module../resources/js/app.js. Steps To ...
Read more >routes is not defined
Clicking the Add button cause this issue: Uncaught ReferenceError: routes is not defined at HTMLElement.
Read more >Ziggy, InertiaJS & Vite : route is not defined
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 >app.js:43519 Uncaught ReferenceError: route is not defined
app.js:43519 Uncaught ReferenceError: route is not defined.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s what my setup looks like, it works without the
@routes
blade directive:In
app.js
:in
webpack.mix.js
:Compiles without errors, and everything works as expected. Hope this helps.
I have the exact same problem. I carefully followed the Artisan section of the readme, after
composer require tightenco/ziggy
.In webpack.mix.js, I added:
In app.js:
Then I generated the ziggy.js file:
php artisan ziggy:generate "resources/js/ziggy.js"
So the ziggy.js file is in the same directory as app.js (you should probably update default location to match new Laravel’s structure BTW)
Then:
npm run dev
Compiles without any problem.
Everything works if I add
@routes
to my blade view, but if I don’t, I get “ReferenceError: Can’t find variable: route”.