Files
advx/src/components/PrivateRoute.tsx
2025-04-10 23:07:21 -03:00

15 lines
391 B
TypeScript

import React from "react";
import { Navigate, Outlet, useLocation } from "react-router-dom";
import { useAuth } from "../contexts/AuthContext";
export const PrivateRoute: React.FC = () => {
const { isAuthenticated } = useAuth();
const location = useLocation();
return isAuthenticated ? (
<Outlet />
) : (
<Navigate to="/login" state={{ from: location }} replace />
);
};