我有一个使用 nuxt-i18n 并忽略路由的多语言 Nuxt 应用程序。
nuxt.config.js
…
seo: true,
parsePages: false,
strategy: 'prefix_except_default',
pages: {
'cats': {
en: '/cats',
de: '/katzen',
fr: false
}
}
…
所以该页面没有法语版本。
我的 lang 开关看起来像这样——到目前为止非常简单:
语言切换.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>
我已更改过滤器以删除丢失的页面/语言,例如:
return this.$i18n.locales.filter(i => (i.code !== this.$i18n.locale) && (this.$nuxt.$route.path !== this.switchLocalePath(i.code)) )
这行得通,但我想要一个更好的解决方案。这是我的问题:如果忽略路由,是否有一种简单的方法可以更改语言主页(/、/en、/de)的路由?