wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 1 | // src/router/index.jsx |
| 2 | import React from 'react' |
| 3 | import { Routes, Route, Navigate, Outlet } from 'react-router-dom' |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 4 | |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 5 | import LoginPage from '../pages/LoginPage/LoginPage' |
| 6 | import RegisterPage from '../pages/RegisterPage/RegisterPage' |
| 7 | import ForgotPasswordPage from '../pages/ForgotPasswordPage/ForgotPasswordPage' |
| 8 | import TestDashboard from '../pages/TestDashboard/TestDashboard' |
| 9 | import HomeFeed from '../components/HomeFeed' |
| 10 | import CreatePost from '../components/CreatePost' |
| 11 | import NotebookPage from '../components/NotebookPage' |
| 12 | import PlaceholderPage from '../components/PlaceholderPage' |
| 13 | import UserProfile from '../components/UserProfile' |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 14 | |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 15 | import AdminPage from '../components/Admin' |
| 16 | import SuperAdmin from '../components/SuperAdmin' |
| 17 | import UserManagement from '../components/UserManagement' |
| 18 | import LogsDashboard from '../components/LogsDashboard' |
| 19 | import TransactionLogs from '../components/TransactionLogs' |
| 20 | import PerformanceLogs from '../components/PerformanceLogs' |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 21 | |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 22 | import { RequireAuth, RequireRole } from './Guards' |
TRM-coding | 85e5c32 | 2025-06-18 19:49:21 +0800 | [diff] [blame] | 23 | |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 24 | export default function AppRoutes() { |
| 25 | return ( |
| 26 | <Routes> |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 27 | {/* ### 公开路由(不用登录就能看) */} |
| 28 | <Route path="/login" element={<LoginPage />} /> |
| 29 | <Route path="/register" element={<RegisterPage />} /> |
| 30 | <Route path="/forgot-password" element={<ForgotPasswordPage />} /> |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 31 | |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 32 | {/* ### 需要登录才能访问的区域 */} |
| 33 | <Route element={<RequireAuth />}> |
| 34 | {/* ---- 普通用户区块 ---- */} |
| 35 | <Route element={<RequireRole allowedRoles={['user']} />}> |
| 36 | <Route path="/home" element={<HomeFeed />} /> |
| 37 | <Route path="/posts/new" element={<CreatePost />} /> |
| 38 | <Route path="/notebooks" element={<NotebookPage />} /> |
| 39 | <Route path="/user/:userId" element={<UserProfile />} /> |
| 40 | <Route path="/activity" element={<PlaceholderPage pageId="activity" />} /> |
| 41 | <Route path="/notes" element={<PlaceholderPage pageId="notes" />} /> |
| 42 | <Route path="/creator" element={<PlaceholderPage pageId="creator" />} /> |
| 43 | <Route path="/journal" element={<PlaceholderPage pageId="journal" />} /> |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 44 | |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 45 | <Route path="/dashboard/*" element={<PlaceholderPage />} /> |
| 46 | <Route path="/posts/new" element={<CreatePost />} /> |
| 47 | <Route path="/posts/edit/:postId" element={<CreatePost />} /> |
| 48 | <Route path="/" element={<Navigate to="/dashboard/overview" replace />} /> |
| 49 | </Route> |
TRM-coding | c4b4f3d | 2025-06-18 19:02:46 +0800 | [diff] [blame] | 50 | |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 51 | {/* ---- 管理员区块 ---- */} |
| 52 | <Route element={<RequireRole allowedRoles={['admin']} />}> |
| 53 | <Route path="/admin" element={<AdminPage />} /> |
| 54 | <Route path="/test-dashboard" element={<TestDashboard />} /> |
| 55 | </Route> |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 56 | |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 57 | {/* ---- 超级管理员区块 ---- */} |
| 58 | <Route element={<RequireRole allowedRoles={['superadmin']} />}> |
| 59 | <Route path="/superadmin" element={<SuperAdmin />}> |
| 60 | <Route index element={<Navigate to="users" replace />} /> |
| 61 | <Route path="users" element={<UserManagement superAdminId={3} />} /> |
| 62 | <Route path="dashboard" element={<LogsDashboard />}> |
| 63 | <Route index element={<Navigate to="transactions" replace />} /> |
| 64 | <Route path="transactions" element={<TransactionLogs userId={1} />} /> |
| 65 | <Route path="performance" element={<PerformanceLogs userId={1} />} /> |
| 66 | </Route> |
| 67 | </Route> |
TRM-coding | 85e5c32 | 2025-06-18 19:49:21 +0800 | [diff] [blame] | 68 | </Route> |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 69 | </Route> |
TRM-coding | 85e5c32 | 2025-06-18 19:49:21 +0800 | [diff] [blame] | 70 | |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 71 | {/* ### 兜底:不认识的地址都重定向到 /login */} |
| 72 | <Route path="*" element={<Navigate to="/login" replace />} /> |
TRM-coding | d1cbf67 | 2025-06-18 15:15:08 +0800 | [diff] [blame] | 73 | </Routes> |
wu | 2f28f67 | 2025-06-19 14:29:30 +0800 | [diff] [blame^] | 74 | ) |
| 75 | } |