tech_mahindra/src/components/ProtectedRoute.tsx
2026-05-22 19:34:42 +05:30

10 lines
394 B
TypeScript

import { Navigate, useLocation } from "react-router-dom";
import { useAuthContext } from "../hooks/AuthContext";
export function ProtectedRoute({ children }: { children: React.ReactNode }) {
const { isAuthenticated } = useAuthContext();
const location = useLocation();
if (!isAuthenticated) return <Navigate to="/login" state={{ from: location }} replace />;
return <>{children}</>;
}