import { Navigate, Outlet } from "react-router-dom";
import PublicNavBar from "../../component/Navbar/PublicNavBar";
/**
* A route component that redirects authenticated users to the dashboard and displays a public navbar
* for unauthenticated users.
*
* @returns {JSX.Element} The public-protected route component.
*/
const PublicProtectedRoute = () => {
/**
* Check if the user is authenticated by looking for a token in local storage.
* If authenticated, redirect to the dashboard.
* If not authenticated, render a public navbar and the nested routes using the Outlet component.
*/
return localStorage.getItem("token") ? (
<Navigate to="/dashboard" />
) : (
<>
<PublicNavBar />
<div
className="route_container"
style={{ marginTop: "95px" }}
>
<Outlet />
</div>
</>
);
};
export default PublicProtectedRoute;
Source