Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue-router error: TypeError: Cannot read property 'matched' of undefined

I'm trying to write my first Vuejs app. I'm using vue-cli and simple-webpack boilerplate.

When I add vue-router links to my app component I get this error in console

Error in render function: "TypeError: Cannot read property 'matched' of undefined"

Here is my code:

App.vue

<template>   <div>     <h2>Links</h2>     <ul>       <router-link to='/'>Home</router-link>       <router-link to='/query'>Query</router-link>        <router-view></router-view>     </ul>   </div> </template>  <script>     export default {} </script> 

main.js

import Vue from 'vue' import VueRouter from 'vue-router'  Vue.use(VueRouter) import routes from './routes.js' import App from './App.vue'  const app = new Vue({   el: '#app',   routes,   render: h => h(App) }) 

routes.js

import VueRouter from 'vue-router'; let routes=[   {     path: '/',     component: require('./Components/Home.vue')   },   {     path: '/query',     component: require('./Components/Query.vue')   } ];  export default new VueRouter({routes}); 
like image 898
Mohammad Reza Avatar asked Jun 18 '17 19:06

Mohammad Reza


2 Answers

The name when you add it to Vue must be router.

import router from './routes.js'  const app = new Vue({   el: '#app',   router,   render: h => h(App) }) 

If, for whatever reason, you want to call the variable routes you could assign it this way.

import routes from './routes.js'  const app = new Vue({   el: '#app',   router: routes,   render: h => h(App) }) 
like image 112
Bert Avatar answered Oct 06 '22 04:10

Bert


vue & vue router & match bug & solution

match bugs

image

image

solution

name must be router

https://stackoverflow.com/a/44618867/5934465

image

OK

image

image


import default module bug

import default module no need {}!

like image 21
xgqfrms Avatar answered Oct 06 '22 04:10

xgqfrms