路由器使用 nuxt-i18n 在 nuxt 中推送区域设置路由

router push a locale route in nuxt with nuxt-i18n

我使用 nuxt-i18n 在我的应用程序中实现国际化。我有一个新闻列表,可以给我这样的路线:

myapp.com/news (default language English)
myapp.com/fr/news
myapp.com/it/news

当我点击新闻时,我想访问 _id 页面,以便仅获取我点击的新闻。所以我用一种方法(onclick)做了这个:

onLoadNews(id) {this.$router.push("/news/" + id);}

但是这样我总是return默认语言是英文。如何以这种方式推送语言环境路由(在方法的函数中)?

this.$router.push(this.localePath({ name: "news-id", params: { id } }));

这对我有用,因为我有一个文件夹 "news" 并且在两个 vue 页面中 index.vue 和 _id.vue.