diff --git a/src/module.ts b/src/module.ts index e0e2927a..1bdfd96f 100644 --- a/src/module.ts +++ b/src/module.ts @@ -99,7 +99,7 @@ export default defineNuxtModule({ dateBuild: Date.now(), baseURL: nuxt.options.app.baseURL, hashMode: nuxt.options?.router?.options?.hashMode ?? false, - globalLocaleRoutes: options.globalLocaleRoutes ?? {}, + globalLocaleRoutes: undefined, } nuxt.options.runtimeConfig.i18nConfig = { rootDir: nuxt.options.rootDir, @@ -135,13 +135,6 @@ export default defineNuxtModule({ addImportsDir(resolver.resolve('./runtime/composables')) - // if (options.includeDefaultLocaleRoute) { - // addServerHandler({ - // middleware: true, - // handler: resolver.resolve('./runtime/server/middleware/i18n-redirect'), - // }) - // } - addServerHandler({ route: '/_locales/:page/:locale/data.json', handler: resolver.resolve('./runtime/server/middleware/i18n-loader'), diff --git a/src/runtime/plugins/01.plugin.ts b/src/runtime/plugins/01.plugin.ts index 6fbb51aa..180a3e66 100644 --- a/src/runtime/plugins/01.plugin.ts +++ b/src/runtime/plugins/01.plugin.ts @@ -144,21 +144,18 @@ function getLocalizedRoute( }) } - if (i18nConfig.includeDefaultLocaleRoute) { - const globalLocaleRoutes = i18nConfig.globalLocaleRoutes ?? {} - if (globalLocaleRoutes[routeName] == false) { - const newParams = resolveParams(to) - delete newParams.locale - return router.resolve({ name: routeName, params: newParams }) - } - } - // Determine the new route name based on locale and configuration const newRouteName = currentLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute ? `localized-${routeName}` : routeName + if (!router.hasRoute(newRouteName)) { + const newParams = resolveParams(to) + delete newParams.locale + return router.resolve({ name: routeName, params: newParams }) + } + const newParams = resolveParams(to) delete newParams.locale diff --git a/src/runtime/plugins/03.define.ts b/src/runtime/plugins/03.define.ts index 6e193c2d..8a2ecb53 100644 --- a/src/runtime/plugins/03.define.ts +++ b/src/runtime/plugins/03.define.ts @@ -13,7 +13,6 @@ export default defineNuxtPlugin(async (_nuxtApp) => { const router = useRouter() const i18nConfig: ModuleOptionsExtend = config.public.i18nConfig as ModuleOptionsExtend - const globalLocaleRoutes = i18nConfig.globalLocaleRoutes ?? {} // Функция нормализации, которая объединяет массивы и объекты в единый массив строк const normalizeLocales = (locales?: string[] | LocalesObject): LocalesObject => { @@ -41,11 +40,6 @@ export default defineNuxtPlugin(async (_nuxtApp) => { .replace(new RegExp(`-${currentLocale}$`), '') if (!to.params.locale) { - const name = to.name?.toString() ?? '' - if (globalLocaleRoutes[name] === false) { - return - } - if (router.hasRoute(`localized-${to.name?.toString()}-${currentLocale}`)) { defaultRouteName = `localized-${to.name?.toString()}-${currentLocale}` } @@ -53,6 +47,10 @@ export default defineNuxtPlugin(async (_nuxtApp) => { defaultRouteName = `localized-${to.name?.toString()}` } + if (!router.hasRoute(defaultRouteName)) { + return + } + const newParams = { ...to.params } newParams.locale = i18nConfig.defaultLocale! @@ -99,16 +97,17 @@ export default defineNuxtPlugin(async (_nuxtApp) => { delete newParams.locale if (i18nConfig.includeDefaultLocaleRoute) { - const name = route.name?.toString() ?? '' - if (globalLocaleRoutes[name] === false) { - return - } if (router.hasRoute(`localized-${defaultRouteName}-${currentLocale}`)) { defaultRouteName = `localized-${defaultRouteName}-${currentLocale}` } else { defaultRouteName = `localized-${defaultRouteName}` } + + if (!router.hasRoute(defaultRouteName)) { + return + } + newParams.locale = i18nConfig.defaultLocale! newParams.name = defaultRouteName }