React Router Redux Sync

4.0.8 · abandoned · verified Tue Apr 21

react-router-redux, specifically version 4.0.8, provided "ruthlessly simple bindings" to keep React Router (versions 2.x and 3.x) and Redux in sync. Its primary purpose was to store React Router's location state within the Redux store, enabling features like time-travel debugging with Redux DevTools. It offered middleware to dispatch navigation actions and a reducer to manage router state. The library itself was noted as 'beta software' in its README. While `react-router-redux` version 5.x was intended for React Router 4.x, the repository for this project has been archived since October 26, 2018, rendering it abandoned. Modern React applications typically use `@reduxjs/toolkit` and `react-router-dom` directly, often with `connected-react-router` (a spiritual successor) or `redux-first-history` for similar state synchronization needs, rather than this deprecated package.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `react-router-redux` with `redux` and `react-router` (v4.x is assumed for `ConnectedRouter` from the README, despite the package version being 4.0.8, implying a common usage pattern at the time of the README update). It shows combining reducers, applying the router middleware, and using `ConnectedRouter` to synchronize browser history with the Redux store.

import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import createHistory from 'history/createBrowserHistory';
import { Route } from 'react-router';
import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux';

// Placeholder for your application's reducers
const reducers = (state = {}, action) => state;

// Placeholder components
const Home = () => <div>Home</div>;
const About = () => <div>About</div>;
const Topics = () => <div>Topics</div>;

// Create a history of your choosing (e.g., browser history)
const history = createHistory();

// Build the middleware for intercepting and dispatching navigation actions
const middleware = routerMiddleware(history);

// Add the routerReducer to your store on the `router` key
// Also apply our middleware for navigating
const store = createStore(
  combineReducers({
    ...reducers,
    router: routerReducer
  }),
  applyMiddleware(middleware)
);

// Example of dispatching a navigation action (can be done from anywhere)
// setTimeout(() => {
//   store.dispatch(push('/about'));
// }, 2000);

ReactDOM.render(
  <Provider store={store}>
    { /* ConnectedRouter will use the store from Provider automatically */ }
    <ConnectedRouter history={history}>
      <div>
        <Route exact path="/" component={Home}/>
        <Route path="/about" component={About}/>
        <Route path="/topics" component={Topics}/>
      </div>
    </ConnectedRouter>
  </Provider>,
  document.getElementById('root')
);

view raw JSON →