Skip to content

Commit

Permalink
refactor: simplify extendSwitchLocalePathIntercepter (#3128)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Sep 24, 2024
1 parent d067336 commit 5caa83b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/runtime/routing/compatibles/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { resolve, routeToObject } from './utils'
import { getLocaleRouteName, getRouteName } from '../utils'
import { extendPrefixable, extendSwitchLocalePathIntercepter, type CommonComposableOptions } from '../../utils'

import type { Strategies, PrefixableOptions, SwitchLocalePathIntercepter } from '../../shared-types'
import type { Strategies, PrefixableOptions } from '../../shared-types'
import type { Locale } from 'vue-i18n'
import type {
RouteLocation,
Expand Down Expand Up @@ -209,8 +209,6 @@ export function resolveRoute(common: CommonComposableOptions, route: RouteLocati
}
}

export const DefaultSwitchLocalePathIntercepter: SwitchLocalePathIntercepter = (path: string) => path

function getLocalizableMetaFromDynamicParams(
common: CommonComposableOptions,
route: RouteLocationNormalizedLoaded
Expand Down
20 changes: 8 additions & 12 deletions src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
localeRoute,
getRouteBaseName,
switchLocalePath,
DefaultPrefixable,
DefaultSwitchLocalePathIntercepter
DefaultPrefixable
} from './routing/compatibles/routing'
import {
getI18nProperty,
Expand Down Expand Up @@ -400,18 +399,15 @@ export function extendPrefixable(runtimeConfig = useRuntimeConfig()) {
// override switch locale path intercepter, support domain
export function extendSwitchLocalePathIntercepter(runtimeConfig = useRuntimeConfig()): SwitchLocalePathIntercepter {
const logger = /*#__PURE__*/ createLogger('extendSwitchLocalePathIntercepter')

return (path: string, locale: Locale): string => {
if (runtimeConfig.public.i18n.differentDomains) {
const domain = getDomainFromLocale(locale)
__DEBUG__ && logger.log({ domain, path })
if (domain) {
return joinURL(domain, path)
} else {
return path
}
} else {
return DefaultSwitchLocalePathIntercepter(path, locale)
if (!runtimeConfig.public.i18n.differentDomains) {
return path
}

const domain = getDomainFromLocale(locale)
__DEBUG__ && logger.log({ domain, path })
return (domain && joinURL(domain, path)) || path
}
}

Expand Down

0 comments on commit 5caa83b

Please sign in to comment.