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'));
I am seeing this same issue. version 6.5.2
me too
Looks like I missed adding routerMiddleware(history) to my middleware and now it is working
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
same issue
Same issue
same issue
I fixed it. I downgraded react-router-dom to v4
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"yield put(push('/x')) works perfectly.Same issue
@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
@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"
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
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
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 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 needconnected-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.
same issue
Same issue, window.location is not a solution
Most helpful comment
@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