- 背景:练习vue路由传参,发现多次点击相同路由控制台会报错 NavigationDuplicated: Avoided redundant navigation to current location: “/home”.
- 解决方法,在router文件夹下的index.js进行配置
/ 解决点击相同路由报错 NavigationDuplicated: Avoided redundant navigation to current location: "/home".
// 尝试了在main.js 中写 push未定义 会报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
注意这里的VueRouter是文档引入路由的变量名,import VueRouter from ‘vue-router’