解决 vue 路由报错 Cannot read property 'beforeRouteEnter' of undefined

简介: 解决 vue 路由报错 Cannot read property 'beforeRouteEnter' of undefined

一、具体路由报错信息

二、为什么会出现这种情况

beforeRouterEnter是页面进入之前调用,所以取不到实例,默认调用 BeforeRouteEntry 钩子导致。

三、解决办法

方法1: 降低vue-router版本

npm i vue-router@2.4.0 将现在的版本降到2.4.0版本以下

方法2: 修改router路由引入方法

{
    path: context.name + '/content/aaa.html',
    name: '/content/aaa.html',
    meta: {
        title: 'hahaha',
        author: "zhangsan"
    },
    component: require('./views/content/aaa.vue').default
},

交流

对前端技术保持学习爱好者。我会经常分享自己所学所看的干货,在进阶的路上,共勉!欢迎关注公众号共同学习。      

相关文章
|
4天前
|
存储 JavaScript 前端开发
成功解决:Cannot read properties of undefined (reading ‘commit‘)
这篇文章提供了解决Vuex中"Cannot read properties of undefined (reading 'commit')"错误的两种方法:检查模板中的数据属性是否存在,以及确保在Vue实例中正确挂载了store对象。
成功解决:Cannot read properties of undefined (reading ‘commit‘)
|
5天前
|
JavaScript
Vue中router路由的使用、router-link的使用(在项目中的实际运用方式)
这篇文章介绍了Vue中router路由和router-link的使用方式,包括router配置、router-link在模板中的使用,以及实现的导航菜单和页面路由效果。
Vue中router路由的使用、router-link的使用(在项目中的实际运用方式)
|
7天前
|
定位技术 Apache
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
18 0
|
7天前
|
JavaScript
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
15 0
|
7天前
|
前端开发 JavaScript
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
18 0
|
2月前
|
前端开发 小程序 JavaScript
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
TypeError: Cannot set properties of undefined (setting ‘resdata‘),res定义数据出现的问题,定义的方法用this换成that
TypeError: Cannot set properties of undefined (setting ‘resdata‘),res定义数据出现的问题,定义的方法用this换成that
Cannot read properties of undefined (reading ‘row‘)
Cannot read properties of undefined (reading ‘row‘)
Cannot read properties of undefined (reading ‘post‘)
Cannot read properties of undefined (reading ‘post‘)
|
1月前
|
JavaScript
element-ui Cannot read properties of undefined (reading ‘name‘),data中写成集合的形式
element-ui Cannot read properties of undefined (reading ‘name‘),data中写成集合的形式