From 4696d3f3644b96648244155a34e43d7b6454da1a Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 17 Apr 2025 11:22:06 +0800 Subject: [PATCH] . --- components/ui/language-switcher.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/components/ui/language-switcher.tsx b/components/ui/language-switcher.tsx index c855b19..76d70f1 100644 --- a/components/ui/language-switcher.tsx +++ b/components/ui/language-switcher.tsx @@ -13,7 +13,6 @@ export function LanguageSwitcher() { const currentLocale = pathname.split('/')[1] || i18nConfig.defaultLocale useEffect(() => { - // 第一次访问页面时,如果 URL 有语言,就记住 if (typeof window !== 'undefined') { const saved = localStorage.getItem('preferred-language') if (!saved || saved !== currentLocale) { @@ -29,15 +28,15 @@ export function LanguageSwitcher() { localStorage.setItem('preferred-language', newLocale) } - // 拆解当前路径 const segments = pathname.split('/') - // 如果路径前缀是语言码,则替换 - const isLocaleInPath = (i18nConfig.locales as unknown as string[]).includes(segments[1]) + // ✅ 修复:类型断言 readonly -> string[] + const localeList = [...i18nConfig.locales] as string[] + const isLocaleInPath = localeList.includes(segments[1]) + if (isLocaleInPath) { segments[1] = newLocale } else { - // 否则插入语言前缀 segments.unshift(newLocale) }