重复点击路由时报错

浏览器报错内容:
vue-router.esm.js?8c4f:2008 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/order".

解决方法一:

//在router/index.js最后添加
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)}

解决方法二:
在点击事件跳转时判断一下路径:

<div :class="{active:$route.path==='/msite'}" @click="goPath('/msite')" class="guideItem">

export default {
    methods: {
        goPath(path){
            //跳转到指定的路由路径
            if(path!==this.$route.path){//解决页面重复跳转报错问题
            this.$router.push(path)
            }
        },     
    },
}
posted @ 2020-12-17 09:05  勿忘归来  阅读(121)  评论(0)    收藏  举报