Uncaught ReferenceError: route is not defined in Laravel 8

Viewed 2883
require('./bootstrap');
require('./ziggy');
window.Vue = require('vue');
const files = require.context('./', true, /\.vue$/i);
files.keys().map(key => {
    return Vue.component(_.last(key.split('/')).split('.')[0], files(key))
});
const app = new Vue({
    el: '#app',
})
Vue.mixin({
    methods: {
        route: route
    }
});

After installing Laravel 8 authentication, I get this error in the console.

app.js:63273 Uncaught ReferenceError: route is not defined at Module../resources/js/app.js (app.js:63273) at webpack_require (app.js:20) at Object.0 (app.js:63334) at webpack_require (app.js:20) at app.js:84 at app.js:87 app.js:58049

Download the Vue Devtools extension for better development. Due to this, my JavaScript is not working properly. I have to hit the URL for an auth module.

2 Answers

in your Root Template (defaults to app.blade.php) (details here), add

@routes

before the line that calls app.js

It happens because of this code. You didnt declare route variable. Because of that it throws error.

Vue.mixin({
methods: {
    route: route
}
});
Related