From 43229a21c058a661ca884e7936f9c9098d63b7a1 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Wed, 22 Oct 2025 15:41:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 66 +++++++++++++++++++++--- src/components/ProtectedRouteRedirect.js | 38 ++++++++++++++ 2 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 src/components/ProtectedRouteRedirect.js diff --git a/src/App.js b/src/App.js index 718c171a..16dc1816 100755 --- a/src/App.js +++ b/src/App.js @@ -47,6 +47,7 @@ import { NotificationProvider, useNotification } from "contexts/NotificationCont // Components import ProtectedRoute from "components/ProtectedRoute"; +import ProtectedRouteRedirect from "components/ProtectedRouteRedirect"; import ErrorBoundary from "components/ErrorBoundary"; import AuthModalManager from "components/Auth/AuthModalManager"; import NotificationContainer from "components/NotificationContainer"; @@ -183,15 +184,66 @@ function AppContent() { } /> - {/* 事件详情独立页面路由 (不经 Admin 布局) */} - } /> + {/* 事件详情独立页面路由 - 需要登录(跳转模式) */} + + + + } + /> {/* 公司相关页面 */} - } /> - } /> - } /> - } /> - } /> + {/* 财报预测 - 需要登录(跳转模式) */} + + + + } + /> + + {/* 财务全景 - 需要登录(弹窗模式) */} + + + + } + /> + + {/* 公司页面 - 需要登录(弹窗模式) */} + + + + } + /> + + {/* 公司详情 - 需要登录(跳转模式) */} + + + + } + /> + + {/* 市场数据 - 需要登录(弹窗模式) */} + + + + } + /> {/* 认证页面路由 - 不使用 MainLayout */} diff --git a/src/components/ProtectedRouteRedirect.js b/src/components/ProtectedRouteRedirect.js new file mode 100644 index 00000000..34d95b0a --- /dev/null +++ b/src/components/ProtectedRouteRedirect.js @@ -0,0 +1,38 @@ +// src/components/ProtectedRouteRedirect.js - 跳转版本 +// 未登录时跳转到首页,用于三级页面(详情页) +import React from 'react'; +import { Navigate } from 'react-router-dom'; +import { Box, VStack, Spinner, Text } from '@chakra-ui/react'; +import { useAuth } from '../contexts/AuthContext'; + +const ProtectedRouteRedirect = ({ children }) => { + const { isAuthenticated, isLoading, user } = useAuth(); + + // 显示加载状态 + if (isLoading) { + return ( + + + + 正在验证登录状态... + + + ); + } + + // 未登录,直接跳转到首页 + if (!isAuthenticated || !user) { + return ; + } + + // 已登录,正常渲染子组件 + return children; +}; + +export default ProtectedRouteRedirect;