重復(fù)點(diǎn)擊路由報(bào)錯(cuò)
vue-router.esm.js?a5e4:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/shop/marketing-center/activity-center"
解決方案:
1晓折、在router文件中增加如下判斷
const router = new VueRouter({
routes: []
})
// 解決重復(fù)點(diǎn)擊相同路由報(bào)錯(cuò)問題
const VueRouterPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push (to) {
return VueRouterPush.call(this, to).catch(err => err);
}
export default router;
2、路由跳轉(zhuǎn)時(shí)判斷是否重復(fù)跳轉(zhuǎn)
handleClickMenu(menu) {
if(this.$route.path !== menu.url){
this.$router.push({path: menu.url});
}
}
3神年、使用catch方法捕獲router.push異常
this.$router.push(route).catch(err => {
console.log('輸出報(bào)錯(cuò)', err);
})