生产管理系统 - 登录页面,注册页面改成nextjs router 跳转
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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() {
|
||||
<div className="mb-6">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => window.location.href = '/login'}
|
||||
onClick={handleNavigateToLogin}
|
||||
className="flex items-center text-sm text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4 mr-2" />
|
||||
|
||||
@@ -21,8 +21,8 @@ export function ClientAuthInterceptor({ children }: ClientAuthInterceptorProps)
|
||||
|
||||
const currentPath = window.location.pathname;
|
||||
|
||||
// 如果已经在认证页面(包括 /login 开头的所有路径),不需要重定向
|
||||
if (currentPath.startsWith('/login')) {
|
||||
// 如果已经在认证页面(包括 /login 开头的所有路径、/register 和根路径),不需要重定向
|
||||
if (currentPath.startsWith('/login') || currentPath === '/register' || currentPath === '/') {
|
||||
console.log(`📄 已在认证页面,跳过拦截: ${currentPath}`);
|
||||
return;
|
||||
}
|
||||
@@ -47,8 +47,8 @@ export function ClientAuthInterceptor({ children }: ClientAuthInterceptorProps)
|
||||
return <LoadingScreen variant="auth" />;
|
||||
}
|
||||
|
||||
// 如果在认证页面(包括 /login 开头的所有路径),直接渲染子组件,不需要认证检查
|
||||
if (currentPath.startsWith('/login')) {
|
||||
// 如果在认证页面(包括 /login 开头的所有路径、/register 和根路径),直接渲染子组件,不需要认证检查
|
||||
if (currentPath.startsWith('/login') || currentPath === '/register' || currentPath === '/') {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user