diff --git a/app/[locale]/login/password/page.tsx b/app/[locale]/login/password/page.tsx index 84de655..8a555ca 100644 --- a/app/[locale]/login/password/page.tsx +++ b/app/[locale]/login/password/page.tsx @@ -7,6 +7,8 @@ import { useEffect, useState } from "react" import { usePathname } from "next/navigation" // 导入 usePathname +import i18nConfig from "@/i18nConfig" + export default function ChangePasswordPage() { const [loading, setLoading] = useState(true) @@ -18,9 +20,27 @@ export default function ChangePasswordPage() { const session = (await supabase.auth.getSession()).data.session if (!session) { - // 提取当前路径中的 locale 部分 - const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en" - router.push(`${locale}/login`) + // // 提取当前路径中的 locale 部分 + // const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en" + + const pathSegments = pathname.split("/").filter(Boolean) + const locales = i18nConfig.locales + const defaultLocale = i18nConfig.defaultLocale + + let locale: (typeof locales)[number] = defaultLocale + + const segment = pathSegments[0] as (typeof locales)[number] + + if (locales.includes(segment)) { + locale = segment + } + const homePath = locale === defaultLocale ? "/" : `/${locale}` + + + + + router.push(`${homePath}/login`) + // router.push(`${locale}/login`) } else { setLoading(false) } diff --git a/components/workspace/delete-workspace.tsx b/components/workspace/delete-workspace.tsx index ff76e35..a272b96 100644 --- a/components/workspace/delete-workspace.tsx +++ b/components/workspace/delete-workspace.tsx @@ -16,6 +16,9 @@ import { FC, useContext, useRef, useState } from "react" import { Input } from "../ui/input" import { useRouter } from "next/navigation" +import { usePathname } from "next/navigation" +import i18nConfig from "@/i18nConfig" + interface DeleteWorkspaceProps { workspace: Tables<"workspaces"> onDelete: () => void @@ -46,7 +49,25 @@ export const DeleteWorkspace: FC = ({ const defaultWorkspace = filteredWorkspaces[0] setSelectedWorkspace(defaultWorkspace) - router.push(`/${defaultWorkspace.id}/chat`) + + + const pathSegments = pathname.split("/").filter(Boolean) + const locales = i18nConfig.locales + const defaultLocale = i18nConfig.defaultLocale + + let locale: (typeof locales)[number] = defaultLocale + + const segment = pathSegments[0] as (typeof locales)[number] + + if (locales.includes(segment)) { + locale = segment + } + const homePath = locale === defaultLocale ? "/" : `/${locale}` + + + + router.push(`${homePath}/${defaultWorkspace.id}/chat`) + // router.push(`/${defaultWorkspace.id}/chat`) return filteredWorkspaces })