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.
Author by
yoyojs
Updated on June 05, 2022Comments
-
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 almost 5 yearsthanks, worth to notice that adding the
_id.vue
makes change the route name tonews-id
. -
grindking over 4 yearsHow 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/1
orstep/2