现象:

image.png

解决方法:打开router文件夹下的index.js文件中添加如下代码


push方法的

image.png

  1. //获取原型对象上的push函数
  2. const originalPush = Router.prototype.push
  3. //修改原型对象中的push方法
  4. Router.prototype.push = function push(location) {
  5. return originalPush.call(this, location).catch(err => err)
  6. }

replace方法的

image.png

  1. const originalPush = VueRouter.prototype.replace
  2. //修改原型对象中的push方法
  3. VueRouter.prototype.replace = function push(location) {
  4. return originalPush.call(this, location).catch(err => err)
  5. }