【vue-router】"Uncaught (in promise) undefined"

vue-router 某些版本在使用 push 和 replace 进行跳转时会出现报错,解决方法如下:

const routerMethods = ['push', 'replace']
routerMethods.forEach(method => {
  const originalCall = VueRouter.prototype[method]
  VueRouter.prototype[method] = function(location, onResolve, onReject) {
    if (onResolve || onReject) {
      return originalCall.call(this, location, onResolve, onReject)
    }
    return originalCall.call(this, location).catch(err => err)
  }
})

参考

https://github.com/vuejs/vue-router/issues/2881#issuecomment-534952949

猜你喜欢

转载自www.cnblogs.com/teemwu/p/12213468.html
今日推荐