【发布时间】:2021-10-30 00:34:51
【问题描述】:
我使用 nuxt 并遇到以下问题。我的旧代码如下所示:
this.$router.push({path: "about/me"})
现在我需要使用一些参数进行相同的调用:
this.$router.push({path: "about/me", params: {sendNotification: "1"}})
这显然不起作用,因为 vue-router 只允许使用 params 和 name 而不是 path,所以它必须看起来像:
this.$router.push({name: ..., params: {sendNotification: "1"}})
我可以用query 而不是params 来做到这一点,但我不希望我的网址看起来很难看。
nuxt 的问题是,或者至少这是我对 nuxt 的理解,它使用文件夹结构生成路由名称,在我的情况下也是语言环境。所以这条路线的名字其实是:“personal-about-me__en”。
所以我的问题是:有没有办法动态获取route.name,所以我可以写如下内容:
this.$router.push({name: getRouteNameByPath("about/me"), params: {sendNotification: "true"}})
【问题讨论】:
标签: vue.js parameters nuxt.js vue-router