This commit is contained in:
hailin 2025-04-17 11:33:33 +08:00
parent caf341f9cd
commit 1ff10621f1
1 changed files with 10 additions and 10 deletions

View File

@ -35,20 +35,20 @@ export function LanguageSwitcher() {
console.log('[LanguageSwitcher] Saved newLocale to localStorage') console.log('[LanguageSwitcher] Saved newLocale to localStorage')
} }
const segments = pathname.split('/') let segments = pathname.split('/').filter(Boolean)
console.log('[LanguageSwitcher] Segments before change:', segments) console.log('[LanguageSwitcher] Segments before change:', segments)
const localeList = [...i18nConfig.locales] as string[] const localeList = [...i18nConfig.locales] as string[]
const isLocaleInPath = localeList.includes(segments[1]) const isLocaleInPath = localeList.includes(segments[0])
console.log('[LanguageSwitcher] isLocaleInPath:', isLocaleInPath) console.log('[LanguageSwitcher] isLocaleInPath:', isLocaleInPath)
if (isLocaleInPath) { if (isLocaleInPath) {
segments[1] = newLocale segments[0] = newLocale
} else { } else {
segments.unshift(newLocale) segments.unshift(newLocale)
} }
const newPath = segments.join('/') const newPath = '/' + segments.join('/')
console.log('[LanguageSwitcher] Final newPath:', newPath) console.log('[LanguageSwitcher] Final newPath:', newPath)
startTransition(() => { startTransition(() => {