Skip to content

Commit acb2ab4

Browse files
suzdalnitskigajus
authored andcommitted
docs: added documentation on using with react-router-redux v5 (#71)
* Added documentation on using with react-router-redux v5 * style: use consistent style with the other examples
1 parent db26f25 commit acb2ab4

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const rootReducer = combineReducers({foo: fooReducer}, StateRecord);
6060

6161
In general, `getDefaultState` function must return an instance of `Immutable.Record` or `Immutable.Collection` that implements `get`, `set` and `withMutations` methods. Such collections are `List`, `Map` and `OrderedMap`.
6262

63-
### Using with `react-router-redux`
63+
### Using with `react-router-redux` v4 and under
6464

6565
`react-router-redux` [`routeReducer`](https://github.com/reactjs/react-router-redux/tree/v4.0.2#routerreducer) does not work with Immutable.js. You need to use a custom reducer:
6666

@@ -101,3 +101,34 @@ const history = syncHistoryWithStore(browserHistory, store, {
101101
```
102102

103103
The `'routing'` path depends on the `rootReducer` definition. This example assumes that `routeReducer` is made available under `routing` property of the `rootReducer`.
104+
105+
### Using with `react-router-redux` v5
106+
To make [`react-router-redux` v5](https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux) work with Immutable.js you only need to use a custom reducer:
107+
108+
```js
109+
import {
110+
Map
111+
} from 'immutable';
112+
import {
113+
LOCATION_CHANGE
114+
} from 'react-router-redux';
115+
116+
const initialState = Map({
117+
location: null,
118+
action: null
119+
});
120+
121+
export function routerReducer(state = initialState, {type, payload = {}} = {}) {
122+
if (type === LOCATION_CHANGE) {
123+
const location = payload.location || payload;
124+
const action = payload.action;
125+
126+
return state
127+
.set('location', location)
128+
.set('action', action);
129+
}
130+
131+
return state;
132+
}
133+
134+
```

0 commit comments

Comments
 (0)