Support changing the router inside a Redux reducer?
thomasjm opened this issue · 0 comments
In some of my Redux reducers I want to simultaneously change the search (i.e. by modifying state.router.location.search
and some other state. Since this library advertises "100% one source of truth (store)" and "100% one-way data flow (only dispatch actions!)", I expected this to work.
If the history were like any other react-redux
component, this change would propagate from the store and the browser URL would be updated. But instead, the browser URL doesn't change and this becomes out of sync with state.router
.
I looked into this and found that the side-effectful calls to history.push
etc. happen inside the router middleware. Thus, to do what I wanted I had to write my own middleware which dispatches router events, so they can cause the desired side effects in the router middleware.
Suggestion: instead, what if the router middleware also examined the state after calling next(action)
, and looked for any change to state.router
? If one is found, then it can again do the necessary history
calls.