Skip to content

console warnin:Duplicate named routes definition #1727

@sailengsi

Description

@sailengsi

我现在有一个这样的场景:
1,默认路由数组只有两个 ,根和登录。
2,登录之后,我会进行动态添加路由,实现方法如下:
this.$router.options.routes = new_routes;
this.$router.addRoutes(this.$router.options.routes);
3,然后退出的时候,再把动态添加的路由干掉,实现方式和上面类似:
this.$router.options.routes = new_routes;//new_routes确定只有两个
this.$router.addRoutes(this.$router.options.routes);
console.log(this.$router.options.routes);//这里也确定只有两个
此时此刻一切都正常,没有任何问题,然而
当我在登录时,重复第二步的操作的时候,会出现以下一大堆警告:

[vue-router] Duplicate named routes definition: { name: "日期时间", path: "/components/form/datetime" }
......
......
凡是在第一次动态添加过的路由,二次动态添加的时候,全部都会出现这些,但功能逻辑操作上,一切都没有问题。

不知道什么原因?或者有没有办法不让显示这个警告,尝试使用
Vue.config.productionTip = false;
Vue.config.devtools = false;
上面这两种方式关闭警告,但对vue-router不好使,查看源码之后,发现开发模式必须会警告,求解决办法。

如果方便,请回复中文,谢谢。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions