Created
October 21, 2016 15:37
-
-
Save bnhansn/5519eadacc3c0c6bfb62069b82c916e1 to your computer and use it in GitHub Desktop.
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
| // @flow | |
| import React from 'react'; | |
| import { Match, Redirect } from 'react-router'; | |
| type Props = { | |
| component: any, | |
| pattern: string, | |
| exactly?: boolean, | |
| isAuthenticated: boolean, | |
| willAuthenticate: boolean, | |
| } | |
| const RedirectAuthenticated = ({ | |
| pattern, | |
| exactly, | |
| isAuthenticated, | |
| willAuthenticate, | |
| component: Component, | |
| }: Props) => | |
| <Match | |
| exactly={exactly} | |
| pattern={pattern} | |
| render={(props) => { | |
| if (isAuthenticated) { return <Redirect to={{ pathname: '/' }} />; } | |
| if (willAuthenticate) { return null; } | |
| if (!willAuthenticate && !isAuthenticated) { return <Component {...props} />; } | |
| return null; | |
| }} | |
| />; | |
| export default RedirectAuthenticated; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment