diff --git a/src/components/Login/LoginForm.tsx b/src/components/Login/LoginForm.tsx index 08f234a..c65c154 100644 --- a/src/components/Login/LoginForm.tsx +++ b/src/components/Login/LoginForm.tsx @@ -68,7 +68,7 @@ export default function LoginForm({ className }: { className?: string }) { if (result.code === 200) { setShowLogin(false); await getUserInfo(); - router.replace(redirect); + if (redirect) router.replace(redirect); } else { setErrorText(result.message); setBtnLoading(false); diff --git a/src/hooks/useLoginRedirect.ts b/src/hooks/useLoginRedirect.ts index fd0e82a..a014717 100644 --- a/src/hooks/useLoginRedirect.ts +++ b/src/hooks/useLoginRedirect.ts @@ -1,8 +1,8 @@ import { useSearchParams } from 'next/navigation'; -export const useLoginRedirect = () => { +export const useLoginRedirect: () => string | null = () => { const searchParams = useSearchParams(); const redirect = searchParams.get('redirect'); - if (!redirect) return '/'; + if (!redirect) return null; return redirect; };