vue项目中路由出现message:"Navigating to current location(xxx) is not allowed "

在vue项目中路由出现message:"Navigating to current location(xxx) is not allowed "的问题

原因:在路由中添加了相同的路由。

解决:

重写路由的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相同路由跳转强制刷新该路由组件

1.在菜单的路由跳转上绑定一个随机query参数,例如时间戳或者随机数:

this.$router.push({

    path:"/xxx",

    query:{

        t:Date.now(),

    },

});

2.在路由容器上绑定key值:

<router-view :key="$route.path + $route.query.t">

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容