侧边栏选中效果修复

This commit is contained in:
liamzi
2025-01-15 11:08:08 +08:00
parent 1eb2e0dd57
commit 3d7b8d705d
6 changed files with 31 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ import React from "react";
import { Navigate, useLocation } from "react-router-dom";
import { useAuth } from "@/contexts/AuthContext";
const PUBLIC_PATHS = ['login', '404'];
const PUBLIC_PATHS = ['login', '404','home'];
export const ProtectedRoute = ({ children }) => {
const { user } = useAuth();
const location = useLocation();
@@ -15,13 +15,12 @@ export const ProtectedRoute = ({ children }) => {
return currentPath === key || currentPath.startsWith(`${key}/`);
});
if (!hasPermission ) {
return <Navigate to="/404" replace />;
if (!hasPermission) {
return <Navigate to="/home" replace />;
}
return children;
}
// 如果用户未登录,重定向到登录页
return <Navigate to="/login" state={{ from: location }} replace />;
};