【问题标题】:router push a locale route in nuxt with nuxt-i18n路由器使用 nuxt-i18n 推送 nuxt 中的区域设置路由
【发布时间】:2019-01-06 10:55:12
【问题描述】:

我使用 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);}

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

【问题讨论】:

    标签: vue.js vue-router nuxt.js


    【解决方案1】:

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

    这对我有用,因为我有一个“新闻”文件夹,并且在两个 vue 页面中有 index.vue 和 _id.vue。

    【讨论】:

    • 谢谢,值得注意的是,添加_id.vue 会使路由名称更改为news-id
    • 如何以编程方式导航到包含当前语言的路线?目前它看起来像这样,但它总是导航到主要语言。 this.$router.push({ path: `step/${this.currentStep + 1}` }); 每一步都是单页,例如step/1step/2
    猜你喜欢
    • 2021-05-08
    • 1970-01-01
    • 2020-06-02
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 2019-03-13
    相关资源
    最近更新 更多