4

I wanted to setup a SPA using Laravel 5.4 and Vue2. I have following a tutorial (Jeffrey Way - Laracast). But i am getting this issue. Can not figure it out why this error in console?? :

Uncaught TypeError: Cannot set property 'app' of undefined
    at VueRouter (app.js:3149)
    at Object.<anonymous> (app.js:4266)
    at __webpack_require__ (app.js:20)
    at Object.<anonymous> (app.js:3343)
    at __webpack_require__ (app.js:20)
    at Object.<anonymous> (app.js:13749)
    at __webpack_require__ (app.js:20)
    at app.js:66
    at app.js:69

Here is my code below :

app.js

import router from './routes';

import './bootstrap';

var app = new Vue({
    el: '#root',
    router
});

routes.js

import VueRouter from 'vue-router';

let routes = [
        {
            path: '/',
            component: require('./views/Home')
        }
    ];

export default VueRouter({
    routes
});

bootstrap.js

import Vue from 'vue';
import VueRouter from 'vue-router';
import axios from 'axios';

window.Vue = Vue;
window.axios = axios;
Vue.use(VueRouter);

window.axios.defaults.headers.common = {
    'X-CSRF-TOKEN': window.Laravel.csrfToken,
    'X-Requested-With': 'XMLHttpRequest'
};
11
  • We can't help without code. Commented Apr 15, 2017 at 19:09
  • Cold you provide your code for tracing the error? Commented Apr 15, 2017 at 19:10
  • @str i have pasted the code here.. take a look Commented Apr 15, 2017 at 19:22
  • @Wei code is here now Commented Apr 15, 2017 at 19:22
  • I can't find 'app' in here, can you find snippet like var app = new Vue({}) Commented Apr 15, 2017 at 19:27

2 Answers 2

12
export default new VueRouter({
  routes
});

add "new"

Sign up to request clarification or add additional context in comments.

Comments

0
let routes = [
        {
            path: '/',
            component: require('./views/Home')
        }
    ];

export default new VueRouter({
    routes
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.