PrivateRoute.js 285 B

12345678910111213
  1. import { Navigate } from 'react-router-dom';
  2. import { history } from '../helpers';
  3. function PrivateRoute({ children }) {
  4. if (!localStorage.getItem('user')) {
  5. return <Navigate to='/login' state={{ from: history.location }} />;
  6. }
  7. return children;
  8. }
  9. export { PrivateRoute };