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' })
wiki
Comments
Post a Comment