Skip to content

lourd/react-router4-redux-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecated

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.


An example for illustrating a possible technical direction for integrating Redux & React Router v4.

Differences

The modified version of react-router-redux is in src/react-router-redux/. The differences are in reducer.js and sync.js.

reducer.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.

sync.js

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.

Dev Instrumentation

I've instrumented the app with a few handy hooks for playing with the app state:

  • dispatch - the store's dispatch is available globally as dispatch
  • Router redux actions - the router redux action creators (push, replace, go, goBack, & goForward) are available globally. Try something like dispatch(push('/bar')) or dispatch(goBack()).
  • history - the history instance is available globally as h. Try something like h.push('/foo').
  • Redux Dev Tools - the store is instrumented to dev tools so you can play around with time travel debugging

About

A demo of integrating Redux & React Router v4

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published