From c6ccdf468f4474e52e6e04ca9266f66487256f2c Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Thu, 13 Oct 2022 02:06:04 +0900 Subject: [PATCH] fix: cannot generate on differentDomains (#1559) --- playground/nuxt.config.ts | 6 +++--- src/runtime/internal.ts | 4 +++- src/runtime/plugin.ts | 2 +- src/runtime/utils.ts | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 8c2a1e64b..aafed95fa 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -23,7 +23,7 @@ export default defineNuxtConfig({ code: 'en', iso: 'en-US', file: 'en.json', - domain: 'localhost:3000', + domain: 'foo.localhost', name: 'English' }, { @@ -42,7 +42,7 @@ export default defineNuxtConfig({ } ], // trailingSlash: true, - // debug: true, + debug: true, defaultLocale: 'en', // strategy: 'no_prefix', // strategy: 'prefix', @@ -53,7 +53,7 @@ export default defineNuxtConfig({ ja: '/about-ja' } }, - // differentDomains: true, + differentDomains: true, detectBrowserLanguage: false, // detectBrowserLanguage: { // // alwaysRedirect: true, diff --git a/src/runtime/internal.ts b/src/runtime/internal.ts index 2f6e6fbcf..285f67b78 100644 --- a/src/runtime/internal.ts +++ b/src/runtime/internal.ts @@ -345,11 +345,13 @@ export function getHost() { } export function getLocaleDomain(locales: LocaleObject[]): string { - const host = getHost() || '' + let host = getHost() || '' if (host) { const matchingLocale = locales.find(locale => locale.domain === host) if (matchingLocale) { return matchingLocale.code + } else { + host = '' } } return host diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index afa16d6ec..5b5731055 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -33,7 +33,7 @@ import { } from '#build/i18n.internal.mjs' import type { Composer, I18nOptions, Locale } from '@intlify/vue-i18n-bridge' -import type { LocaleObject, RouteLocationNormalized, ExtendProperyDescripters } from 'vue-i18n-routing' +import type { LocaleObject, ExtendProperyDescripters } from 'vue-i18n-routing' import type { NuxtApp } from '#imports' type GetRouteBaseName = typeof getRouteBaseName diff --git a/src/runtime/utils.ts b/src/runtime/utils.ts index f6561d0c5..47a6310b9 100644 --- a/src/runtime/utils.ts +++ b/src/runtime/utils.ts @@ -310,7 +310,7 @@ export async function navigate( if (process.client) { window.location.assign(redirectPath) } else if (process.server) { - // TODO: + __DEBUG__ && console.log('differentDomains servermode ', redirectPath) } } } @@ -351,6 +351,7 @@ export function extendSwitchLocalePathIntercepter( return (path: string, locale: Locale): string => { if (differentDomains) { const domain = getDomainFromLocale(locale, normalizedLocales, nuxt) + __DEBUG__ && console.log('extendSwitchLocalePathIntercepter: domain -> ', domain, ' path -> ', path) if (domain) { return joinURL(domain, path) } else {