acdlite / redux-router

Redux bindings for React Router – keep your router state inside your Redux store
MIT License
2.3k stars 216 forks source link

pushState works in ComponentWillReceiveProps. But doesn't work when I directly dispatch is as part of an action. #243

Closed xinghengwang closed 8 years ago

xinghengwang commented 8 years ago

I want to using pushState to redirect user after he does something. function someAction () { return dispatch => { dispatch(someOtherAction); //this modifies the state. dispatch(pushState('newroute'); } } but the dispatch pushState doesn't seems to work. However, in ComponentWillReceiveProps (I do a pushState, it works.) Any thoughts on why this is the case?

mjrussell commented 8 years ago

@xinghengwang what does your create store look like? One thing I could think of is that because you are using redux-thunk the order of the store enhancer with the middleware could cause the action not to get picked up. I'd be interested to know if you see the dispatched action in redux-logger when you use the action creator

xinghengwang commented 8 years ago

I am using this template: https://github.com/erikras/react-redux-universal-hot-example I forked it a while ago (when it was still on redux router, even though latest version has updated to redux-react-router), but createStore is pretty much the same:

https://github.com/erikras/react-redux-universal-hot-example/blob/ad0c0ad6d69013b7ac9bf1454dfaef0381873188/src/redux/create.js

mjrussell commented 8 years ago

I think this is a duplicate of https://github.com/acdlite/redux-router/issues/191. Can you try some of the advice in https://github.com/acdlite/redux-router/issues/191#issuecomment-167249778