webapps/packages/layers/content/middleware/content-routing.global.ts
Dominik Milacher 4a872ad1c6
Some checks failed
Build and deploy updated apps / Build & deploy (push) Failing after 1m6s
Fix pre-rendering
2025-10-14 16:08:03 +02:00

21 lines
700 B
TypeScript

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