From dba0371580faf98653b12f26d4a070226cd97634 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 21 Apr 2025 01:22:08 +0800 Subject: [PATCH] . --- components/utility/profile-settings.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/components/utility/profile-settings.tsx b/components/utility/profile-settings.tsx index 5ce978d..958607a 100644 --- a/components/utility/profile-settings.tsx +++ b/components/utility/profile-settings.tsx @@ -47,6 +47,7 @@ import { usePathname } from "next/navigation" // 导入 usePathname import { useTranslation } from "react-i18next"; // 引入useTranslation用于国际化 +import i18nConfig from "@/i18nConfig" interface ProfileSettingsProps {} @@ -133,9 +134,20 @@ export const ProfileSettings: FC = ({}) => { const handleSignOut = async () => { await supabase.auth.signOut() - console.log(`...................Redirecting to: /${locale}/login`) - - router.push(`/${locale}/login`) + const pathSegments = pathname.split("/").filter(Boolean) + const locales = i18nConfig.locales + const defaultLocale = i18nConfig.defaultLocale + + let locale = defaultLocale + + // 动态判断首段是否是合法语言代码 + if (locales.includes(pathSegments[0])) { + locale = pathSegments[0] + } + + const loginPath = locale === defaultLocale ? "/login" : `/${locale}/login` + + router.push(loginPath) router.refresh() return }