解决Uncaught (in promise) TypeError: Cannot read property '_normalized' of of undefined报错

错误:
vue-router.esm.js?fe87:971 Uncaught (in promise) TypeError: Cannot read property ‘_normalized’ of undefined
at normalizeLocation (vue-router.esm.js?fe87:971)
at Object.match (vue-router.esm.js?fe87:1486)
at VueRouter.match (vue-router.esm.js?fe87:2730)
at HTML5History.transitionTo (vue-router.esm.js?fe87:2071)
at HTML5History.push (vue-router.esm.js?fe87:2403)
at eval (vue-router.esm.js?fe87:2815)
at new Promise ()
at VueRouter.push (vue-router.esm.js?fe87:2814)
at VueComponent.activated (home.vue?250d:25)
at invokeWithErrorHandling (vue.runtime.esm.js?ff9b:1854)

在组件的activated函数中调用router.push方法时出现的,虽然报错了,但路由跳转是成功的…很奇怪
解决方法:
在配置路由的js文件重写push方法

const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

你可能感兴趣的:(vue)