Last active
July 13, 2020 21:47
-
-
Save cesar4rroyo/874ee2c162cf472b925715cdd664acd7 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 PublicRoute = ({ | |
isAuthenticated, | |
component: Component, | |
...rest | |
}) => { | |
return ( | |
<Route | |
{...rest} | |
component={(props) => | |
!isAuthenticated ? ( | |
<Component {...props} /> | |
) : ( | |
<Redirect to="/" /> | |
) | |
} | |
></Route> | |
); | |
}; | |
PublicRoute.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