1

I have huge vue application with a lot of <router-link> and :to.

I just implement i18n in my application. now I need to add the $i18n.locale prefix to each router-link.

for example:

 <router-link :to="`${i18n.locale}/login`">…</router-link>

Is there easy way to add the locale prefix without change all the router-link or :to in my code?

Jon Sud
  • 10,211
  • 17
  • 76
  • 174
  • Did you try that https://stackoverflow.com/questions/50321530/prefix-routes-with-locale-in-vue-js-using-vue-i18n? It seems to be related to your question. – NikitaK Aug 06 '19 at 14:26
  • yes, but is a different question because I have set the router to be :lang like in the stackoverfow question. my question is about the router-link link. when I have link and now I need to add prefix for every router-link – Jon Sud Aug 06 '19 at 14:32
  • I thought (didn't check, just a suggestion) that `router-link` with `to: "/login"` which is placed inside child route (parent route will have `path: "/:lang"`) will do that automatically: `/en` will be taken from parent `route` and `/login` will be taken from `router-link` in nested view... – NikitaK Aug 06 '19 at 16:20

0 Answers0