Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not work differentDomains #1770

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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