vue router Uncaught (in promise)

原因: 没有使用catch捕获方法

解决方法: 重写 Router 原型链上的 push、replace 方法

import Router from 'vue-router'

const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

猜你喜欢

转载自www.cnblogs.com/guangzan/p/12244563.html