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)
}
posted @ 2020-03-27 03:51  guangzan  阅读(394)  评论(0编辑  收藏  举报