Skip to content

Commit

Permalink
fix: not work differentDomains (nuxt-modules#1770)
Browse files Browse the repository at this point in the history
* fix: not work differentDomains

* fix
  • Loading branch information
kazupon committed Dec 26, 2022
1 parent ab13714 commit 8f7e2b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/runtime/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,9 @@ export function getDomainFromLocale(localeCode: Locale, locales: LocaleObject[],
}
let protocol
if (process.server) {
// @ts-ignore TODO: fix type error
const { req } = useRequestEvent(nuxt)
const {
node: { req }
} = useRequestEvent(nuxt)
protocol = req && isHTTPS(req) ? 'https' : 'http'
} else {
protocol = window.location.protocol.split(':')[0]
Expand Down
21 changes: 18 additions & 3 deletions src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
localeHead,
LocaleObject,
DefaultPrefixable,
DefaultSwitchLocalePathIntercepter
DefaultSwitchLocalePathIntercepter,
getComposer,
useSwitchLocalePath
} from 'vue-i18n-routing'
import { navigateTo, useState } from '#imports'
import { isString, isFunction, isArray, isObject } from '@intlify/shared'
Expand Down Expand Up @@ -310,8 +312,21 @@ export function detectRedirect<Context extends NuxtApp = NuxtApp>(
}

if (differentDomains || (isSSG && process.client)) {
const routePath = context.$switchLocalePath(targetLocale) || context.$localePath(route.fullPath, targetLocale)
__DEBUG__ && console.log('detectRedirect: calculate domain routePath -> ', routePath)
/**
* `$router.currentRoute` does not yet reflect the `to` value,
* when the Router middleware handler is executed.
* if `$switchLocalePath` is called, the intended path cannot be obtained,
* because it is processed by previso's route.
* so, we don't call that function, and instead, we call `useSwitchLocalePath`,
* let it be processed by the route of the router middleware.
*/
const switchLocalePath = useSwitchLocalePath({
i18n: getComposer(context.$i18n),
route,
router: context.$router
})
const routePath = switchLocalePath(targetLocale)
__DEBUG__ && console.log('detectRedirect: calculate domain or ssg routePath -> ', routePath)
if (isString(routePath)) {
redirectPath = routePath
}
Expand Down

0 comments on commit 8f7e2b6

Please sign in to comment.