Using react-router-redux
If, considering the concerns in the previous section, you decide you want to deeply integrate react-router with Redux: That is what we are going to do in this section!
Installing react-router-redux
As always, we first need to install the libraries via npm
:
npm install --save react-router-redux@next npm install --save history
Using the routerMiddleware
Next, we need to make react-router use the Redux store. This is done by applying the routerMiddleware
provided by react-router-redux when creating the Redux store. Perform the following steps:
- Edit
src/store/middleware.js
and import therouterMiddleware
:
import { routerMiddleware } from 'react-router-redux'
- The middleware requires us to pass a history object to it. So we also import the
createHistory
helper from the history library:
import createHistory from 'history/createBrowserHistory'
- Now, we use this helper function to create a new
history
object and export it:
export const history = createHistory()
- Then, pass the
middleware...