From b771297b97abd13ec2d539160b3fddb7992bb9a8 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 18 Apr 2025 17:23:02 +0800 Subject: [PATCH] . --- app/[locale]/login/password/page.tsx | 4 +++- components/utility/change-password.tsx | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/[locale]/login/password/page.tsx b/app/[locale]/login/password/page.tsx index a8e5f42..84de655 100644 --- a/app/[locale]/login/password/page.tsx +++ b/app/[locale]/login/password/page.tsx @@ -5,10 +5,13 @@ import { supabase } from "@/lib/supabase/browser-client" import { useRouter } from "next/navigation" import { useEffect, useState } from "react" +import { usePathname } from "next/navigation" // 导入 usePathname + export default function ChangePasswordPage() { const [loading, setLoading] = useState(true) const router = useRouter() + const pathname = usePathname() // 获取当前路径 useEffect(() => { ;(async () => { @@ -16,7 +19,6 @@ export default function ChangePasswordPage() { if (!session) { // 提取当前路径中的 locale 部分 - const pathname = router.pathname const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en" router.push(`${locale}/login`) } else { diff --git a/components/utility/change-password.tsx b/components/utility/change-password.tsx index 3cadaa3..fa22ea9 100644 --- a/components/utility/change-password.tsx +++ b/components/utility/change-password.tsx @@ -1,6 +1,7 @@ "use client" import { supabase } from "@/lib/supabase/browser-client" +import { usePathname } from "next/navigation" // 导入 usePathname import { useRouter } from "next/navigation" import { FC, useState } from "react" import { Button } from "../ui/button" @@ -18,6 +19,9 @@ interface ChangePasswordProps {} export const ChangePassword: FC = () => { const router = useRouter() + const pathname = usePathname() // 获取当前路径 + + const [newPassword, setNewPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") @@ -30,7 +34,6 @@ export const ChangePassword: FC = () => { toast.success("Password changed successfully.") // 提取当前路径中的 locale 部分 - const pathname = router.pathname const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en" // 将 locale 添加到跳转 URL 中