Files
new-api/web/src/components/PrivateRoute.js

13 lines
285 B
JavaScript
Raw Normal View History

2023-04-22 20:39:27 +08:00
import { Navigate } from 'react-router-dom';
import { history } from '../helpers';
function PrivateRoute({ children }) {
if (!localStorage.getItem('user')) {
2024-03-23 21:24:39 +08:00
return <Navigate to='/login' state={{ from: history.location }} />;
2023-04-22 20:39:27 +08:00
}
return children;
}
2024-03-23 21:24:39 +08:00
export { PrivateRoute };