ProtectedRoute.tsx (380B)
1 import { Navigate, Outlet } from "react-router"; 2 3 type ProtectedRouteProps = { 4 children?: React.ReactNode, 5 isAllowed: boolean, 6 redirectPath?: string, 7 }; 8 9 export default function ProtectedRoute({ children, isAllowed, redirectPath = "/" }: Readonly<ProtectedRouteProps>) { 10 if (!isAllowed) { 11 return <Navigate to={redirectPath} replace />; 12 } 13 14 return children || <Outlet />; 15 };