ProtectedRoute.tsx
309 Bytes
import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { isLoggedIn } from '../auth/localAuth';
export function ProtectedRoute() {
const location = useLocation();
if (!isLoggedIn()) {
return <Navigate to="/login" replace state={{ from: location }} />;
}
return <Outlet />;
}