在vue項(xiàng)目中路由出現(xiàn)message:"Navigating to current location(xxx) is not allowed "的問(wèn)題
原因:在路由中添加了相同的路由。
解決:
重寫路由的push方法
在src/router/index.js 里面import Router from 'vue-router'下面寫入下面方法即可
/**
* 重寫路由的push方法
*/
const routerPush = Router.prototype.push
Router.prototype.push = functionpush(location){
? return routerPush.call(this, location).catch(error=> error)
}
vue相同路由跳轉(zhuǎn)強(qiáng)制刷新該路由組件
1.在菜單的路由跳轉(zhuǎn)上綁定一個(gè)隨機(jī)query參數(shù),例如時(shí)間戳或者隨機(jī)數(shù):
this.$router.push({
? ? path:"/xxx",
? ? query:{
? ? ? ? t:Date.now(),
? ? },
});
2.在路由容器上綁定key值:
<router-view :key="$route.path + $route.query.t">