Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

router push a locale route in nuxt with nuxt-i18n

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?

like image 344
yoyojs Avatar asked Jul 30 '18 08:07

yoyojs


1 Answers

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.

like image 198
yoyojs Avatar answered Sep 16 '22 18:09

yoyojs