intlify / nuxt3

Nuxt 3 Module for vue-i18n-next

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use localePath() in middleware

max5432112345 opened this issue · comments

export default defineNuxtRouteMiddleware((to, from) => {
  const nuxtApp = useNuxtApp()
  const locales = nuxtApp.vueApp.i18n.availableLocales // locales localeCodes
  const isLocalised = locales.some(locale => to.fullPath.startsWith('/' + locale))
  
  if (!isLocalised) {
    return navigateTo(localePath(to))
  }
}

or how to get fallback locale?