VueRouter is not defined
You have to tell Vue to use VueRouter using the method Vue.use()
first. So, do:
import VueRouter from 'vue-router'
# add this code
Vue.use(VueRouter)
var router = new VueRouter({
routes: [
{path: 'home', component: homeComponent}
]
})
UPDATED:
First install vue-router using
npm install --save vue-router
Then import and use it like
import VueRouter from 'vue-router'
Then use it in vue
Vue.use(VueRouter)
Then define your routes:
const routes = [
{path: '/', component: SomeComponent}
]
then initialize the router and pass it the routes
var router = new VueRouter({
routes: routes,
mode: 'history'
})
Pass router to vuejs then profit :)
new Vue({
el: '#root',
router: router
})
You forgot to use the Vue.use
method, here's how you do it:
Vue.use(VueRouter) // use the imported router as the parameter.