Files
react-template/src/components/protected-route/index.tsx
T
2025-03-26 19:06:46 +08:00

13 lines
371 B
TypeScript

import { Navigate, Outlet, useLocation } from "react-router"
import { useAppSelector } from "@/store"
export const ProtectedRoute = () => {
const isAuthenticated = useAppSelector((state) => state.auth.isAuthenticated)
const location = useLocation()
if (isAuthenticated) {
return <Navigate to="" state={{ from: location }} replace />
}
return <Outlet />
}