react-router-redux push function not working from epic ?
See original GitHub issueHi guys,
Thanks for this powerful middleware.
I am trying to push new route from epic function using push
function of react-router-redux
but seems push is not firing!
import * as ajax from '../../utils/ajax';
import {
FETCH_PRODUCTS_REQUEST,
} from '../actions/actionTypes';
import { doFetchProductsFulfilled } from '../actions/doFetchProducts';
import { push } from 'react-router-redux';
export default function epicFetchProducts(action$, store, { queryString }) {
return action$.ofType(FETCH_PRODUCTS_REQUEST)
.map(function(action){
store.dispatch(
push('/fooo' )
)
const searchString = queryString.stringify(action.atts)
return Object.assign({}, action, {
searchString
})
})
.mergeMap(action =>
ajax.get(`/products?${action.searchString}`)
.map(response => doFetchProductsFulfilled(response))
);
}
Here is my module versions -
- “history”: “^4.6.3”
- “react-redux”: “^5.0.5”
- “react-router”: “^4.1.2”
- “react-router-dom”: “^4.1.2”
- “react-router-redux”: “^5.0.0-alpha.6”
Is there any guideline/implementations for this ?
Thank you in advance!
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
`push` from "connected-react-router" used in redux ...
`push` from "connected-react-router" used in redux-observable epic doesn't change the url and renders empty page - Stack Overflow. Stack ...
Read more >redux-observable/redux-observable - Gitter
I am trying to push new route from epic function using push function of react-router-redux but seems push is not firing! import {...
Read more >How to Transition to Another Route on Successful Async ...
There are several ways to redirect a user to another route, including the history.push() method and the <Redirect /> component from react-router ......
Read more >How to use the react-router-redux.push function in react ... - Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >Reactive Apps with Redux, RxJS, and Redux-Observable
Explore what reactive programming using RxJS is and build a React Native ... Redux is one solution to this problem by keeping the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had a similar issue today. I noticed it was my configuration issue with
react-router-redux 5.x
(used withreact-router 4.x
).Pay close attention to README’s usage guide. Key things to lookout are (see the README’s code for details):
routerReducer
with a key ofrouter
when creating the store.routerMiddleware
when creating the store (I forgot this).Once that is done, you should be able to navigate to another route by calling
push
from an epic like this:Notice that I call
push()
(this function returnsRouterAction
) withinmapTo()
. This is to avoid dispatching from within the epic (i.e. anti-pattern mentioned above).For anyone struggling with this, I had a similar problem when calling the push method from within an epic. I could see the action ‘router/CALL_HISTORY_METHOD’ in redux dev tools but the actual URL wasn’t being changed. The problem simply was that middlewares were being applied to the redux store in the wrong order. This is the working store configuration