router push a locale route in nuxt with nuxt-i18n

10,856

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

that worked for me because i have a folder "news" and inside two vue pages the index.vue and the _id.vue.

Share:
10,856
yoyojs
Author by

yoyojs

Updated on June 05, 2022

Comments

  • yoyojs
    yoyojs almost 2 years

    I use nuxt-i18n to get internationalization in my application. I have a list of news that gives me routes like that :

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

    when i click on a news i want to reach th _id page to get only only the news i clicked on. so i did this in a method (onclick) :

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

    But this way I always return to English default language. How to push a locale route (in the function of a method) this way?

  • kojot
    kojot almost 5 years
    thanks, worth to notice that adding the _id.vue makes change the route name to news-id.
  • grindking
    grindking over 4 years
    How can I navigate to a route programmatically including the current language? Currently it looks like this but it always navigates to the main language. this.$router.push({ path: `step/${this.currentStep + 1}` }); Every step is single page e.g. step/1or step/2