Vue-Router报错

431 阅读1分钟

Avoided redundant navigation to current...

避免重复跳转到当前路由
在vue项目中路由跳转过程中浏览器会报Avoided redundant navigation to current location...这个错误,解决方法就是在路由文件里添加

const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

解决Vue跳转相同路由时,页面不刷新

在用户点击某个导航时,跳转这个路由,当用户再次点击该导航时候,再次刷新这个路由

//在路由跳转的时候加上一个时间戳
this.$router.push({
	name:"...",
    query:{
    	t:Date.now(),
    }
})
<!--然后在`<router-view>`上加上key属性,值为时间戳-->
<router-view :key="$router.query.t" />