美文网首页
为什么`router.addRoutes()` 添加的路由在 t

为什么`router.addRoutes()` 添加的路由在 t

作者: 莫伊剑客 | 来源:发表于2021-01-14 11:10 被阅读0次
如果你指的是动态路由通过 this.$router.options 找不到,这是 vue-router 故意这么设计的,曾经有人和你一样以为这是 Bug 而提了 Issus (https://github.com/vuejs/vue-router/issues/1859)

如果您非要这么做,可以使用一下方法将动态添加的路由添加到this.$router.options中

let newRoutes=[]
this.$router.addRoutes(newRoutes)
this.$router.options.routes=this.$router.options.routes.concat(newRoutes)

相关文章

网友评论

      本文标题:为什么`router.addRoutes()` 添加的路由在 t

      本文链接:https://www.haomeiwen.com/subject/sbzmaktx.html