fix: 修复后台菜单路由匹配和概览重定向循环

This commit is contained in:
que01 committed 2026-10-15 17:50:30 +08:00
1 parent bf4bbf81c7
commit 34bd8142de
4 files changed
+78 -4

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
import { createElement, type ReactNode } from "react";
import { Navigate, Route, Routes } from "react-router-dom";
export function AdminOverviewRedirect() {
return createElement(Navigate, { to: "/admin/overview", replace: true });
}
export function AdminRouter({ children }: { children: ReactNode }) {
return createElement(
Routes,
null,
createElement(Route, { path: "/admin/*", element: children }),
createElement(Route, { path: "*", element: createElement(AdminOverviewRedirect) }),
);
}
+4 -3
View File
@@ -31,7 +31,8 @@ import { adminMessage as message } from "../components/AdminMessage.js";
import { AdminButton } from "../components/AdminButton.js";
import { AdminSelect } from "../components/AdminSelect.js";
import { AdminLayout } from "../components/AdminLayout.js";
import { Navigate, Route, Routes } from "react-router-dom";
import { Route, Routes } from "react-router-dom";
import { AdminOverviewRedirect } from "./AdminRouter.js";
import { Suspense } from "react";
export function Dashboard({ onLogout, role }: { onLogout: () => void; role: string }) {
@@ -127,7 +128,7 @@ export function Dashboard({ onLogout, role }: { onLogout: () => void; role: stri
<div className="admin-content-inner">
<Suspense fallback={<LoadingStack />}>
<Routes>
<Route path="/" element={<Navigate to="overview" replace />} />
<Route index element={<AdminOverviewRedirect />} />
<Route path="overview" element={<FeatureOverviewPage />} />
<Route
path="publication"
@@ -144,7 +145,7 @@ export function Dashboard({ onLogout, role }: { onLogout: () => void; role: stri
<Route path="members" element={<FeatureMembersPage />} />
</>
)}
<Route path="*" element={<Navigate to="overview" replace />} />
<Route path="*" element={<AdminOverviewRedirect />} />
</Routes>
</Suspense>
</div>
+6 -1
View File
@@ -1,6 +1,7 @@
import React, { useState } from "react";
import { ChangePassword, Login } from "../features/auth/AuthPages.js";
import { Dashboard } from "./Dashboard.js";
import { AdminRouter } from "./AdminRouter.js";
import { adminMessage as message } from "../components/AdminMessage.js";
export function Root() {
@@ -34,5 +35,9 @@ export function Root() {
/>
);
if (mustChangePassword) return <ChangePassword onComplete={() => setMustChangePassword(false)} />;
return <Dashboard onLogout={logout} role={role} />;
return (
<AdminRouter>
<Dashboard onLogout={logout} role={role} />
</AdminRouter>
);
}