Created
October 20, 2021 15:47
-
-
Save hieptl/7dbabd7a3f71faed65187ef4b12dc544 to your computer and use it in GitHub Desktop.
PrivateRoute.tsx - Ionic Chat App
This file contains hidden or 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. | |
import React from 'react'; | |
// import react router. | |
import { Route, Redirect } from 'react-router-dom'; | |
const PrivateRoute: React.FC<any> = ({ component: Component, ...rest }: any) => { | |
return ( | |
// Show the component only when the user is logged in | |
// Otherwise, redirect the user to /signin page | |
<Route {...rest} render={props => ( | |
localStorage.getItem('auth') ? | |
<Component {...props} /> | |
: <Redirect to="/login" /> | |
)} /> | |
); | |
}; | |
export default PrivateRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment