根据 mac 地址屏蔽导航栏入口
This commit is contained in:
+28
-7
@@ -18,6 +18,7 @@ import SelectPage, { consumeSelectReturnScroll } from "./pages/SelectPage";
|
||||
import CommunityPage from "./pages/CommunityPage";
|
||||
import ChangelogPage from "./pages/ChangelogPage";
|
||||
import { AIDrawerProvider } from "./contexts/AIDrawerContext";
|
||||
import { NavConfigProvider, useNavConfig } from "./contexts/NavConfigContext";
|
||||
import DesktopAIShell from "./components/DesktopAIShell";
|
||||
import { appShellColumnClass, appShellOuterClass } from "./lib/appShell";
|
||||
|
||||
@@ -74,6 +75,23 @@ function SelectScrollRestore() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* NavRouteGuard — 当某个导航入口被 MAC 隐藏配置屏蔽时,
|
||||
* 拦截对应路由(如直接访问 /ai),重定向到 /404。
|
||||
* 首页 "/" 永不拦截,避免锁死。
|
||||
*/
|
||||
function NavRouteGuard() {
|
||||
const [location, setLocation] = useLocation();
|
||||
const { isPathHidden } = useNavConfig();
|
||||
useEffect(() => {
|
||||
if (location === "/") return;
|
||||
if (isPathHidden(location)) {
|
||||
setLocation("/404", { replace: true });
|
||||
}
|
||||
}, [location, isPathHidden, setLocation]);
|
||||
return null;
|
||||
}
|
||||
|
||||
function AppRouter() {
|
||||
return (
|
||||
<Switch>
|
||||
@@ -104,14 +122,17 @@ function App() {
|
||||
<Toaster />
|
||||
<Router hook={useHashLocation}>
|
||||
<AIDrawerProvider>
|
||||
<SelectScrollRestore />
|
||||
<div className={appShellOuterClass}>
|
||||
<div className={appShellColumnClass}>
|
||||
<DesktopAIShell>
|
||||
<AppRouter />
|
||||
</DesktopAIShell>
|
||||
<NavConfigProvider>
|
||||
<SelectScrollRestore />
|
||||
<NavRouteGuard />
|
||||
<div className={appShellOuterClass}>
|
||||
<div className={appShellColumnClass}>
|
||||
<DesktopAIShell>
|
||||
<AppRouter />
|
||||
</DesktopAIShell>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</NavConfigProvider>
|
||||
</AIDrawerProvider>
|
||||
</Router>
|
||||
</TooltipProvider>
|
||||
|
||||
Reference in New Issue
Block a user