connected-react-router: In redux-saga, the put(push('/xxx')) is not work

In redux-saga, the put(push(‘/xxx’)) is not work,the code is :

import { put } from 'redux-saga/effects';
import { push } from 'connected-react-router';

yield put(push('/xxx'));

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 24
  • Comments: 19

Most upvoted comments

@danielgatis I’ve removed the <Router></Router> of react-router-dom and it started working properly. I don’t know if this is the correct approach but it worked for me. Thanks

looks dirty, but putting yield delay(0) before yield put(push('/')) helped

I fixed it by upgrading react-redux to react-reudx@7.1.0 Here are my dependencies:

  • "react-redux": "^7.1.0"
  • "connected-react-router": "^6.5.0" So yield put(push('/x')) works perfectly. I hope it will help someone

Same issue, window.location is not a solution

I solved temporarily by replacing push with window.location, it will look like this:

import { call } from 'redux-saga/effects';

function* mySagaFunction() {
  try {
    const response = yield call(someAPIcall);
    if (response.data) {
      window.location = response.data.myNewUrl;
    }
  } catch (err) {
    // Some error handling
  }
}

And it’s working now. I hope it helps somebody

Looks like I missed adding routerMiddleware(history) to my middleware and now it is working