Vue3.1版本出现中此异常,在路由器中添加如下代码

//先把原来的push方法保存起来
const originPush = VueRouter.prototype.push
const originReplace = VueRouter.prototype.replace
//把原来的push修改为另外一个方法
VueRouter.prototype.push = function(location,resolved,rejected){
  if(resolved === undefined && rejected === undefined){
    return originPush.call(this,location).catch(() => {})
  }else{
    return originPush.call(this,location,resolved,rejected)
  }
}

VueRouter.prototype.replace = function(location,resolved,rejected){
  if(resolved === undefined && rejected === undefined){
    return originReplace.call(this,location).catch(() => {})
  }else{
    return originReplace.call(this,location,resolved,rejected)
  }
}
posted on 2021-07-21 08:38  文种玉  阅读(43)  评论(0编辑  收藏  举报