57 lines
2.5 KiB
React
57 lines
2.5 KiB
React
import { Routes, Route, Navigate, useLocation } from 'react-router-dom'
|
|
import MobileShell from './layouts/MobileShell.jsx'
|
|
import LoginPage from './pages/LoginPage.jsx'
|
|
import MacroPage from './pages/MacroPage.jsx'
|
|
import MonitorPage from './pages/MonitorPage.jsx'
|
|
import ServerDetail from './pages/monitor/ServerDetail.jsx'
|
|
import MePage from './pages/MePage.jsx'
|
|
import CheckinPage from './pages/checkin/CheckinPage.jsx'
|
|
import TaskPage from './pages/task/TaskPage.jsx'
|
|
import { useAuth } from './auth/AuthContext.jsx'
|
|
import { PowerSyncProvider } from './lib/powersync/react.jsx'
|
|
|
|
// 默认落地页: 打卡 (V0.2 起打卡是第一个 Tab 且为默认选中)
|
|
const HOME_PATH = '/checkin'
|
|
|
|
// 已登录访问 /login 自动回默认页
|
|
function RedirectIfAuthed({ children }) {
|
|
const { user, loading } = useAuth()
|
|
if (loading) return null
|
|
if (user) return <Navigate to={HOME_PATH} replace />
|
|
return children
|
|
}
|
|
|
|
// 未登录访问受保护页面 → 跳 /login
|
|
function RequireAuth({ children }) {
|
|
const { user, loading } = useAuth()
|
|
const location = useLocation()
|
|
if (loading) return <div className="page-loading">加载中...</div>
|
|
if (!user) return <Navigate to="/login" state={{ from: location }} replace />
|
|
return children
|
|
}
|
|
|
|
export default function App() {
|
|
return (
|
|
<PowerSyncProvider>
|
|
<Routes>
|
|
<Route path="/login" element={<RedirectIfAuthed><LoginPage /></RedirectIfAuthed>} />
|
|
<Route element={<RequireAuth><MobileShell /></RequireAuth>}>
|
|
{/* 打卡为默认首页 */}
|
|
<Route path="/" element={<Navigate to={HOME_PATH} replace />} />
|
|
<Route path="/checkin" element={<CheckinPage />} />
|
|
{/* 任务模块 (V0.2): 首屏(最近项目+当前项目) / 项目列表 / 深链 (T-VW-08/09) */}
|
|
<Route path="/task" element={<TaskPage />} />
|
|
<Route path="/task/list" element={<TaskPage />} />
|
|
<Route path="/task/:pid" element={<TaskPage />} />
|
|
{/* 宏观: 报警 / 新闻 / 油价 / 经济数据 / 策略研究 / 经济文章 (V0.2 原首页并入, 默认新闻) */}
|
|
<Route path="/macro" element={<Navigate to="/macro/news" replace />} />
|
|
<Route path="/macro/*" element={<MacroPage />} />
|
|
<Route path="/monitor" element={<MonitorPage />} />
|
|
<Route path="/monitor/server/:uuid" element={<ServerDetail />} />
|
|
<Route path="/me" element={<MePage />} />
|
|
</Route>
|
|
<Route path="*" element={<Navigate to={HOME_PATH} replace />} />
|
|
</Routes>
|
|
</PowerSyncProvider>
|
|
)
|
|
} |