[Vuejs]-Nuxt-i18n fallback ignored routes

0👍

I have solved the problem by simply wrapping an additional function around it:

<nav id="language-switch" v-if="isOpen" class="language-switch__nav arrow arrow--top">
  <ul class="language-switch__list">
    <li class="language-switch__item" v-for="locale in availableLocales">
      <NuxtLink class="language-switch__link" rel="alternate" :key="locale.code" :to="switchLocalePathFallback(locale.code)" :hreflang="locale.code" :lang="locale.code" active-class="none" exact>{{locale.name}}</NuxtLink>
    </li>
  </ul>
</nav>
…
computed: {
  availableLocales () {
    return this.$i18n.locales.filter(i => (i.code !== this.$i18n.locale) )
  }
},
methods: {
  switchLocalePathFallback(code) {
    let langPath = this.switchLocalePath(code),
        path = langPath
    if(langPath == this.$nuxt.$route.path ) {
      path = this.$i18n.defaultLocale != code ? '/'+code : '/'
    }
    return path
  }
}
…

Not very flexible but it works for me.

Leave a comment