Some checks failed
Build and deploy updated apps / Build & deploy (push) Failing after 1m3s
21 lines
703 B
TypeScript
21 lines
703 B
TypeScript
export default defineNuxtRouteMiddleware((to, from) => {
|
|
// important: routes do not exist in middleware, never (in)directly use e.g. useRoute
|
|
|
|
if (import.meta.prerender) {
|
|
return // it will interfere with pre-rendering otherwise
|
|
}
|
|
|
|
const {getLocaleVariant, buildPrefix} = useContentPrefix()
|
|
const localeVariant = getLocaleVariant(to.path)
|
|
|
|
if (to.matched.length && localeVariant) return
|
|
|
|
if (!to.matched.length && localeVariant) {
|
|
const [locale, variant] = localeVariant
|
|
return navigateTo(buildPrefix(locale, variant))
|
|
}
|
|
|
|
const {preferredLocale, preferredVariant} = useContentPreference()
|
|
return navigateTo(buildPrefix(preferredLocale.value, preferredVariant.value))
|
|
})
|