How to change url after successful api call in saga

Use Case:

After the user has subscribed, I want to go to another page that informs the user about checking their email.

  try {
    const request = yield call(subcribe, action.payload.data)
    yield put({ type: SUBSCRIBE_SUCCESS, payload: request.data })
    yield put(showNotification(NOTIFICATION_SUCCESS, 'Please check your email.'))
  } catch(e) {
    ...
  }

is there any way to go to ie success page /subscribe-successafter I received a successful response from the server?

+4
source share
1 answer

If you get a successful response from your server, you should change the status of the summary to something like subsribeSuccess: true. So that you have the opportunity to check this state in the component component of WillReceiveProps (nextProps) and make browserHistory.push ('subscribe-success').

Here is an example:

, {... state, subscribeSuccess: true} , SUBSCRIBE_SUCCESS.

:

componentWillReceiveProps(nextProps){
  if(myConnectedReduxState.subscribeSuccess){
    browserHistory.push('subscribe-success');
  }
}

, , . -.

+4

Source: https://habr.com/ru/post/1655054/


All Articles