react-router-redux
    Overview
    Documentation
    Insights
    Code
    Contributors
    Dependencies
    Alternatives

react-router-redux

Ruthlessly simple bindings to keep react-router and redux in sync

4.0.8  •  Published 3 years ago  •  by reactjs  •  MIT License

npm version npm downloads build status

Keep your state in sync with your router

This is beta software, it needs:

  1. A working example
  2. Some people to try it out and find bugs
  3. A strategy for working with the devtools
    • (issue describing a different approach to what we’ve seen previously coming soon)

Versions

This (react-router-redux 5.x) is the version of react-router-redux for use with react-router 4.x. Users of react-router 2.x and 3.x want to use react-router-redux found at the legacy repository.

Installation

npm install --save react-router-redux@next
npm install --save history

Usage

Here’s a basic idea of how it works:

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'

import reducers from './reducers' // Or wherever you keep your reducers

// Create a history of your choosing (we're using a browser history in this case)
const history = createHistory()

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

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

// Now you can dispatch navigation actions from anywhere!
// store.dispatch(push('/foo'))

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')
)
How do you feel about the name Devstore for this site?

Popularity

Weekly Downloads
440.3K
Stars
8.0K

Maintenance

Development

Last ver 3 years ago
Created 4 years ago
Last commit 1 year ago
3 days between commits

Technology

Node version: 6.2.1
0 unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

77 contributors
Tim Dorr
Maintainer, 129 commits, 54 merges, 5 PRs
Works at SalesLoft
James Long
Maintainer, 101 commits, 49 merges, 6 PRs
Kim Joar Bekkelund
Maintainer, 38 commits, 11 merges, 15 PRs
Lee Bannard
15 commits, 7 PRs
Justin Greenberg
7 commits, 6 PRs
Kai Curry
5 commits, 4 PRs
Works at CAPE.io

Tags

react
redux
router
Ready for the next level?
Join Devstore's founding team to help us build the ultimate open-source app store, work with the latest technologies, and enjoy great culture, impact and autonomy
© 2019 Devstore, Inc.
Devstore helps developers find and use open-source packages, so they can focus on building amazing things