文章

VUE路由重复报错问题

VUE 路由重复报错问题

VUE路由重复报错问题

VUE 路由重复报错问题

1622771811744-ed6984fa-579e-471a-a229-c38b2a108827.png

在router/index.js文件内写

解决方法1:修改push

1
2
3
4
5
6
7
8
9
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

解决方法2:修改replace

1
2
3
4
5
6
7
8
9
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
//获取原型对象上的replace函数
const originalReplace = VueRouter.prototype.replace
//修改原型对象中的replace方法
VueRouter.prototype.replace = function replace (location) {
  return originalReplace.call(this, location).catch(err => err)
}
本文由作者按照 CC BY 4.0 进行授权