Skip to content

Instantly share code, notes, and snippets.

@acilsd
Created February 21, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acilsd/62371deaa316aedbcc6b3f984850b91d to your computer and use it in GitHub Desktop.
Save acilsd/62371deaa316aedbcc6b3f984850b91d to your computer and use it in GitHub Desktop.
private_route_mobx_edition
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