From aec67101cbfeea6a15d17262097b7f63f80b5267 Mon Sep 17 00:00:00 2001 From: peng Date: Tue, 4 Nov 2025 10:59:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E7=AE=A1=E7=90=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=20-=20=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E9=A1=B5=E9=9D=A2=E6=94=B9=E6=88=90nextjs=20?= =?UTF-8?q?router=20=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crop-x/src/app/(auth)/login/page.tsx | 5 ++++- crop-x/src/app/(auth)/register/page.tsx | 15 +++++++++++++-- .../src/components/auth/ClientAuthInterceptor.tsx | 8 ++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/crop-x/src/app/(auth)/login/page.tsx b/crop-x/src/app/(auth)/login/page.tsx index b7fdc16..33a5d61 100644 --- a/crop-x/src/app/(auth)/login/page.tsx +++ b/crop-x/src/app/(auth)/login/page.tsx @@ -8,13 +8,16 @@ 'use client'; import React from 'react'; +import { useRouter } from 'next/navigation'; import { SmartFieldBackground } from '@/components/auth/SmartFieldBackground'; import { Shield } from 'lucide-react'; import { LoginForm } from './components/LoginForm'; export default function LoginPage() { + const router = useRouter(); + const handleRegisterClick = () => { - window.location.href = '/register'; + router.push('/register'); }; return ( diff --git a/crop-x/src/app/(auth)/register/page.tsx b/crop-x/src/app/(auth)/register/page.tsx index 16e09f7..0194f3f 100644 --- a/crop-x/src/app/(auth)/register/page.tsx +++ b/crop-x/src/app/(auth)/register/page.tsx @@ -8,6 +8,7 @@ 'use client'; import React, { useEffect, useState } from 'react'; +import { useRouter } from 'next/navigation'; import { Card } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; @@ -38,7 +39,17 @@ import { toast } from 'sonner'; export default function RegisterPage() { const { login } = useAuth(); + const router = useRouter(); const [loading, setLoading] = useState(false); + + // 导航方法封装 + const handleNavigateToLogin = () => { + router.push('/login'); + }; + + const handleNavigateToHome = () => { + router.push('/'); + }; const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [sendingCode, setSendingCode] = useState(false); @@ -229,7 +240,7 @@ export default function RegisterPage() { enterpriseName: enterprises.find(e => e.id === form.enterpriseId)?.name || '', createdAt: new Date().toISOString(), }); - window.location.href = '/'; + handleNavigateToHome(); }, 1500); } else { setError('短信验证码错误'); @@ -264,7 +275,7 @@ export default function RegisterPage() {