Last active
July 13, 2020 21:50
-
-
Save cesar4rroyo/bd14c71e7e00f0b75e1c539737df1123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { Redirect, Route } from "react-router-dom"; | |
import PropTypes from "prop-types"; | |
export const PrivateRoute = ({ | |
isAuthenticated, | |
component: Component, | |
...rest | |
}) => { | |
return ( | |
<Route | |
{...rest} | |
component={(props) => | |
isAuthenticated ? ( | |
<Component {...props} /> | |
) : ( | |
<Redirect to="/login" /> | |
) | |
} | |
></Route> | |
); | |
}; | |
PrivateRoute.propTypes = { | |
isAuthenticated: PropTypes.bool.isRequired, | |
component: PropTypes.func.isRequired, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment