reactjs - React Router Redirect Conditional -




i'm trying make button redirects user new page after validation completed correctly.

is there way of doing this? how route activated inside of class method?

import validator './validator';  class example {    constructor(props) {     super(props)     this.saveandcontinue = thos.saveandcontinue.bind(this)   }    saveandcontinue () {     var valid = validator.validate(this.props.form)     if (valid) {       axios.post('/path')       <redirect to='/other_tab'>     } else {       validator.showerrors()     }   }    render() {     <button onclick={this.saveandcontinue}>save , continue</button>   }  } 

as discussed should have access history object via this.props.history described here.

if push function redirect route need. example:

// use push, replace, , go navigate around. this.props.history.push('/home', { some: 'state' }) 

https://reacttraining.com/react-router/web/api/history





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -