React from React-Router routing to log in to verify control

This article introduces the method of logging in to verify control from React-Router routing, sharing it to everyone, specifically:

Verification code

 Import React from 'React'Import {Connect} from' React-REDUX ' .AuthenticatedComponent) {return Component.AuthenticatedComponent} // create a validation component class AuthenticatedComponent extends React.Component {static contextTypes = {router: React.PropTypes.object.isRequired,} state = {login: true,} componentWillMount () {this. CHECKAUTH ();} ComponentWillReceiveProps (NextProps) {this.checkauth ();} checkauth () {// Judgment login const token = this.props.token; const login = token? token.login: null; // Not landing Oriented to login page if (! Login) {let redirect = this.props.location.pathname +; this.context.router.push ( '? / login message = 401 & redirect_uri =' + encodeURIComponent (redirect)); return;} this.setState ({login}); } render () {if (this.state.login) {return } return ''}} // do not use it directly react-redux return // Component.AuthenticatedComponent = AuthenticatedComponent // return Component.AuthenticatedComponent function mapStateToProps ( state) {return {token: state.token,};} function mapDispatchToProps (dispatch) {return {};} Component.AuthenticatedComponent = connect (mapStateToProps, mapDispatchToProps) (AuthenticatedComponent); return Component.AuthenticatedComponent}   

      The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Clouds. 
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment