问题
- vue项目中重复点击菜单导航报错
- 路由重复
解决
在router/index.js文件内添加代码
- 方法一:
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) }
- 方法二:
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) } }