├── .babelrc
├── .gitignore
├── README.md
├── package.json
├── src
├── containers
│ ├── About.js
│ ├── App.js
│ ├── Home.js
│ ├── Subpage.js
│ └── index.js
├── index.js
├── reducers
│ ├── app-reducer.js
│ └── router-reducer.js
└── redux-router-init.js
├── static
└── images
│ └── us.png
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "es2015",
4 | "react"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Example: React + Router + Redux + Immutable.js
2 |
3 | This is a barebones working [React](https://facebook.github.io/react/) application that demonstrates combining [React Router](https://github.com/reactjs/react-router) and [Redux](http://redux.js.org/) using an [Immutable.js](https://facebook.github.io/immutable-js/) store. We use [Babel](https://babeljs.io/) to transpile ES6 to ES5 that can be run in the browser and [Webpack](https://webpack.github.io/) to trigger Babel and pack the results.
4 |
5 | ## Motivation:
6 |
7 | * React Router to efficiently manage multiple areas of the app
8 | * Redux to keep a clean, reproducible state
9 | * Immutable.js to make manipulations of state easier and more disciplined
10 |
11 | ## Overview
12 |
13 | I started with a plain React application, then added React Router. I extended this with a Redux store for managing state. I used the [react-router-redux](https://github.com/reactjs/react-router-redux) package to help manage the interplay between these two packages.
14 |
15 | If you want your Redux store itself to be immutable, then you to modify things a little bit from the default Redux setup. The [redux-immutable](https://github.com/gajus/redux-immutable) package gets us most of the distance out-of-the-box, but there's [some more customization you to need to do](https://github.com/gajus/redux-immutable#using-with-react-router-redux) when combining Redux, Immutable.js, AND React Router.
16 |
17 | My goal was to provide a **working example** of combining all these packages and snippets together.
18 |
19 | **Note**: I'm using `hashHistory` intentionally since for my use case we are supporting older versions of Internet Explorer and don't want route changes to cause a reload when `browserHistory` is not supported. See [more info](https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#hashhistory).
20 |
21 | ## Getting started
22 |
23 | Install required dependencies with
24 |
25 | npm install
26 |
27 | You can then run the webpack development server on http://localhost:3000/ with
28 |
29 | npm start
30 |
31 | You also can build the webpack results and save them to the `dist/` folder with
32 |
33 | npm build
34 |
35 |
36 | ## Resources
37 |
38 | Kudos and hat-tips to all the people involved in creating React, Redux, React Router, Immutable.js, Babel, Webpack, React-router-redux, redux-immutable and the authors of the following resources.
39 |
40 | * [redux-immutable] [Using react-immutable with react-router-redux](https://github.com/gajus/redux-immutable#using-with-react-router-redux)
41 | * [react-router-redux] [Brief overview of how to use react router and redux with an Immutable.js store](https://github.com/reactjs/react-router-redux#what-if-i-use-immutablejs-with-my-redux-store)
42 | * [react-router-redux] [Instructions on configuring react-router-redux with an Immutable.js store ](https://github.com/reactjs/react-router-redux/issues/301)
43 | The `createSelectLocationState` function defined here is crucial and is only found at this link and this other [issue](https://github.com/reactjs/react-router-redux/issues/314#issuecomment-190678756)
44 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-router-redux-immutable",
3 | "version": "1.0.0",
4 | "description": "An example React app using React Router, Redux and Immutable.js",
5 | "main": "index.js",
6 | "scripts": {
7 | "build": "webpack --progress --colors --config webpack.config.js && cp -r static/* dist/",
8 | "start": "webpack-dev-server --progress --colors --config webpack.config.js"
9 | },
10 | "author": "",
11 | "license": "MIT",
12 | "dependencies": {
13 | "babel-core": "^6.9.1",
14 | "babel-loader": "^6.2.4",
15 | "babel-plugin-react-transform": "^2.0.2",
16 | "babel-preset-es2015": "^6.9.0",
17 | "babel-preset-react": "^6.5.0",
18 | "history": "^3.0.0",
19 | "html-webpack-plugin": "^2.21.0",
20 | "immutable": "^3.8.1",
21 | "react": "0.14.8",
22 | "react-dom": "0.14.8",
23 | "react-redux": "^4.4.5",
24 | "react-router": "^2.4.1",
25 | "react-router-redux": "^4.0.5",
26 | "redux": "^3.5.2",
27 | "redux-immutable": "^3.0.6",
28 | "webpack": "^1.13.1",
29 | "webpack-dev-server": "^1.14.1"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/containers/About.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default class extends React.Component {
4 | render () {
5 | return