操作:
在VUE项目中点击两次路由切换
原因:
在路由跳转的时候同一个路由多次添加
是不被允许的
解决方案(两种):
1.切换版本回3.0版本
2.重写路由的push方法【在src/router/index.js 里面import Router from 'vue-router'
下面写入下面方法即可】
import Vue from 'vue' //如果已引用,不需要重复引用
import Router from 'vue-router'; //如果已引用,不需要重复引用
Vue.use(Router) //如果已引用,不需要重复引用
/**
* 重写路由的push方法
*/
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
return routerPush.call(this, location).catch(error=> error)
}