Steven Musumeche Steven Musumeche - 2 months ago 44
React JSX Question

Redirect to another route after submission success

I'm using redux-form and react-router. Redux-form provides a method called

onSubmitSuccess
which is called after successful submission. However, I don't have access to the router in that method.

How can I redirect to a new route using react-router after a successful submission?

Answer

I would suggest you use container component for this. Once your form is submitted, dispatch an action and in that action use browserHistory to change or replace the route.

//container code
function mapDispatchToProps(dispatch){
  return{
    onSubmit : () =>{
        dispatch(updateData())
   }
 }

}

//action code
 function updateData(){
    //update state if needed
    browserHistory.push(//changed route)
 }