I've a multilang Nuxt App using nuxt-i18n with ignored routes.
nuxt.config.js
…
seo: true,
parsePages: false,
strategy: 'prefix_except_default',
pages: {
'cats': {
en: '/cats',
de: '/katzen',
fr: false
}
}
…
So the page is not available in french.
My lang switch looks like this – pretty simple so far:
LanguageSwitch.vue
computed: {
availableLocales () {
return this.$i18n.locales.filter(i => i.code !== this.$i18n.locale)
}
}
<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="switchLocalePath(locale.code)"
:hreflang="locale.code" :lang="locale.code"
active-class="none"
exact>
{{locale.name}}
</NuxtLink>
</li>
</ul>
I've changed the filter to remove missing pages/languages like that:
return this.$i18n.locales.filter(i => (i.code !== this.$i18n.locale) && (this.$nuxt.$route.path !== this.switchLocalePath(i.code)) )
That works, but I'd like a better solution. Here is my question: Is there an easy way to change the routes to the language homepage (/,/en,/de) if the route is ignored?