connected-react-router icon indicating copy to clipboard operation
connected-react-router copied to clipboard

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

Open qingyang-id opened this issue 4 years ago • 19 comments

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'));

qingyang-id avatar Jul 18 '19 12:07 qingyang-id

I am seeing this same issue. version 6.5.2

heshamnaim avatar Aug 02 '19 23:08 heshamnaim

me too

Gxxxxxer avatar Aug 04 '19 06:08 Gxxxxxer

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

heshamnaim avatar Aug 04 '19 18:08 heshamnaim

export const history = createHistory(); // ======================================================== // Store Instantiation // ======================================================== const initialState = {}; const enhancers = []; const middlewares = [thunk, routerMiddleware(history)];

// ======================================================== // Developer Tools Setup // ======================================================== if (process.env.NODE_ENV === 'development') { const { logger } = require('redux-logger'); // eslint-disable-line

middlewares.push(logger);

const devToolsExtension = window.REDUX_DEVTOOLS_EXTENSION; // eslint-disable-line

if (typeof devToolsExtension === 'function') { enhancers.push(devToolsExtension()); } }

const composedEnhancers = compose( applyMiddleware(...middlewares), ...enhancers );

export const store = createStore( combineReducers({ router: connectRouter(history), rootReducer }), initialState, composedEnhancers );

in redux, the put(push('/xxx')) is not work

Gxxxxxer avatar Aug 05 '19 06:08 Gxxxxxer

same issue

nicofrem avatar Aug 07 '19 22:08 nicofrem

Same issue

Thebarda avatar Aug 12 '19 13:08 Thebarda

same issue

sldone avatar Aug 13 '19 08:08 sldone

I fixed it. I downgraded react-router-dom to v4

sldone avatar Aug 14 '19 05:08 sldone

I fixed it by upgrading react-redux to [email protected] 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

Thebarda avatar Aug 14 '19 09:08 Thebarda

Same issue

ctkc avatar Aug 29 '19 16:08 ctkc

@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

ctkc avatar Sep 02 '19 12:09 ctkc

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

dospolov avatar Feb 13 '20 23:02 dospolov

@ctkc I use ConnectedRouter instead of Router. Still not working.

The issue still exists in "connected-react-router": "^6.6.1" "react-redux": "^6.0.1" "redux-saga": "^1.0.2"

AkshayHere avatar Feb 18 '20 03:02 AkshayHere

You could try some something similar to what is mentioned in this comment. Hope it helps. https://github.com/supasate/connected-react-router/issues/177#issuecomment-437145983

AkshayHere avatar Feb 18 '20 03:02 AkshayHere

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

adolfogustavo avatar Oct 24 '20 04:10 adolfogustavo

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 a weird workaround. For what in this case you need connected-react-router?

sldone avatar Oct 26 '20 09:10 sldone

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 a weird workaround. For what in this case you need connected-react-router?

I need it to redirect my user to a different URL, I also tried to use replace but didn't work and I cannot update / downgrade connected-react-router for now due to some internal policies.

adolfogustavo avatar Oct 27 '20 15:10 adolfogustavo

same issue

emmanuelsio avatar Nov 20 '20 09:11 emmanuelsio

Same issue, window.location is not a solution

Aziaev avatar Dec 16 '20 20:12 Aziaev