Created
February 21, 2019 11:27
-
-
Save acilsd/62371deaa316aedbcc6b3f984850b91d to your computer and use it in GitHub Desktop.
private_route_mobx_edition
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
interface IProps extends RouteProps { | |
component: React.SFC<any> | React.ComponentClass<any>; | |
auth?: IAuthStore; | |
} | |
const PrivateRoute = inject('auth')( | |
observer(({ component: Component, auth, ...rest }: IProps) => { | |
return ( | |
<Route | |
{...rest} | |
render={props => | |
auth.isAuthorized ? ( | |
<Component {...props} /> | |
) : ( | |
<Redirect | |
to={{ | |
pathname: '/login', | |
state: { from: props.location } | |
}} | |
/> | |
) | |
} | |
/> | |
); | |
}) | |
); | |
export default PrivateRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment