webapps/packages/layers/content/middleware/content-routing.global.ts
Dominik Milacher e41a99cd95
Some checks failed
Build and deploy updated apps / Build & deploy (push) Failing after 1m0s
Try something
2025-10-14 18:05:17 +02:00

17 lines
606 B
TypeScript

export default defineNuxtRouteMiddleware((to, from) => {
// important: routes do not exist in middleware, never (in)directly use e.g. useRoute
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))
})