React Router's API changed between the v4 alphas and the release version, making this code irrelevant. If you're looking for Redux-React Router v4 bindings I recommend checking out Connected React Router.
React Router v4 w/ React Router Redux Demo
An example for illustrating a possible technical direction for integrating Redux & React Router v4.
The modified version of react-router-redux
is in src/react-router-redux/
. The differences are in reducer.js
and sync.js
.
reducer.js
exports a factory function createReducer
that takes history
. The reducer needs access to the history
instance so it can set its initial state properly.
Syncing the store with the history is now much simpler thanks to a one-way flow of state. It has an order of magnitude less code (~10 lines vs ~100 lines), and there's no more internal state. We simply subscribe to the history and dispatch an action to the store with the given location
and action
.
I've instrumented the app with a few handy hooks for playing with the app state:
dispatch
- the store's dispatch is available globally asdispatch
- Router redux actions - the router redux action creators (
push
,replace
,go
,goBack
, &goForward
) are available globally. Try something likedispatch(push('/bar'))
ordispatch(goBack())
. history
- the history instance is available globally ash
. Try something likeh.push('/foo')
.- Redux Dev Tools - the store is instrumented to dev tools so you can play around with time travel debugging