前端:React 19 + Vite 8 + Tailwind 4 博客与管理后台 SPA
- 渲染管线(§8.2):react-markdown + remark-gfm + rehype-sanitize (GitHub schema 扩展 hljs class 与 checked)+ rehype-highlight 纯 class 高亮;链接强制 target=_blank + rel=nofollow noopener noreferrer; schema 快照与恶意 Markdown 冒烟测试(vitest 6 用例) - 编辑器:CodeMirror 6 源码编辑 + 分屏实时预览 + 工具栏 + 粘贴/拖拽图片上传;slug 首存定稿(冲突 409 就地高亮)、 摘要留空自动截取、2s 防抖自动保存 - 页面:博客首页(置顶/分页/标签云)、详情(面包屑/上一篇下一篇)、 标签页、登录、管理列表/回收站/设置/改密、404 - lib:api 客户端(统一包络 + 内存态 CSRF,禁 localStorage)、 AuthContext(/api/me 重取)、暗色主题(class 切换 + 系统跟随) - index.html 内嵌 Go template 占位符供服务端 meta 注入; vite base 固定 '/'(防深链白屏);/api 代理 127.0.0.1:8080
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { Navigate, Route, Routes } from 'react-router'
|
||||
import type { ReactNode } from 'react'
|
||||
import { useAuth } from './lib/auth'
|
||||
import { BlogLayout, AdminLayout } from './components/Layout'
|
||||
import Home from './pages/Home'
|
||||
import Note from './pages/Note'
|
||||
import TagPage from './pages/TagPage'
|
||||
import Login from './pages/Login'
|
||||
import AdminList from './pages/AdminList'
|
||||
import AdminTrash from './pages/AdminTrash'
|
||||
import AdminEdit from './pages/AdminEdit'
|
||||
import AdminSettings from './pages/AdminSettings'
|
||||
import NotFound from './pages/NotFound'
|
||||
|
||||
// 登录守卫:401 统一跳转 /admin/login(§8.2)
|
||||
function RequireAuth({ children }: { children: ReactNode }) {
|
||||
const { authenticated, loading } = useAuth()
|
||||
if (loading) {
|
||||
return <div className="flex min-h-screen items-center justify-center text-zinc-500">加载中…</div>
|
||||
}
|
||||
if (!authenticated) {
|
||||
return <Navigate to="/admin/login" replace />
|
||||
}
|
||||
return <>{children}</>
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route element={<BlogLayout />}>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/notes/:slug" element={<Note />} />
|
||||
<Route path="/tags/:tag" element={<TagPage />} />
|
||||
</Route>
|
||||
<Route path="/admin/login" element={<Login />} />
|
||||
<Route element={<RequireAuth><AdminLayout /></RequireAuth>}>
|
||||
<Route path="/admin" element={<AdminList />} />
|
||||
<Route path="/admin/trash" element={<AdminTrash />} />
|
||||
<Route path="/admin/settings" element={<AdminSettings />} />
|
||||
<Route path="/admin/notes/new" element={<AdminEdit />} />
|
||||
<Route path="/admin/notes/:id/edit" element={<AdminEdit />} />
|
||||
</Route>
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Routes>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user