关于vue-router Cannot read property 'matched' of undefined的问题


按照官方设置写的路由,卡在了Cannot read property 'matched' of undefined这个错误问题,查了很多资料才知道,有两上命名是不能改动的,route与router; 在目录新建了文件router.js

import Vue from 'vue'
import vueRouter from 'vue-router';
import login from './pages/member/login.vue';
import App from './App.vue';
Vue.use(vueRouter);
const routes=[{path:'/user/login',component:login},{path:"*",component:App}];
const router=new vueRouter({routes});
export default router;

这儿为什么可以直接将路由定义数组传入VueRouter中呢?因为实例中对路由定义的数组的命名是routes。注释中写了routes相当于routes:routes
那么如果我们的路由定义数组名称不是routes当然是不能使用简写的。就要乖乖的写成 routes:routes3或其他方式routes3不一定是你自己的路由定义数组名称,请替换成自己的就行

参考资料:https://blog.csdn.net/marswill/article/details/74368939


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM