Skip to content

Commit

Permalink
fix: cannot generate on differentDomains (#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Oct 12, 2022
1 parent 1585fd4 commit c6ccdf4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default defineNuxtConfig({
code: 'en',
iso: 'en-US',
file: 'en.json',
domain: 'localhost:3000',
domain: 'foo.localhost',
name: 'English'
},
{
Expand All @@ -42,7 +42,7 @@ export default defineNuxtConfig({
}
],
// trailingSlash: true,
// debug: true,
debug: true,
defaultLocale: 'en',
// strategy: 'no_prefix',
// strategy: 'prefix',
Expand All @@ -53,7 +53,7 @@ export default defineNuxtConfig({
ja: '/about-ja'
}
},
// differentDomains: true,
differentDomains: true,
detectBrowserLanguage: false,
// detectBrowserLanguage: {
// // alwaysRedirect: true,
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export async function navigate<Context extends NuxtApp = NuxtApp>(
if (process.client) {
window.location.assign(redirectPath)
} else if (process.server) {
// TODO:
__DEBUG__ && console.log('differentDomains servermode ', redirectPath)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c6ccdf4

Please sign in to comment.