# react-router-redux-bind

> Redux bindings for React Router Next v4

Latest version **0.2.1** (published 2017-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-router-redux-bind
pnpm add react-router-redux-bind
yarn add react-router-redux-bind
bun add react-router-redux-bind
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2017-02-13 |
| First published | 2017-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | MaxSvargal |
| Maintainers | maxsvargal |
| Keywords | react, router, redux, redux-saga, history, route, routing, link, connect, isomorphic, universal |

## Links

- npm: https://www.npmjs.com/package/react-router-redux-bind
- Repository: https://github.com/MaxSvargal/react-router-redux-bind
- Homepage: https://github.com/MaxSvargal/react-router-redux-bind#readme
- Issues: https://github.com/MaxSvargal/react-router-redux-bind/issues
- npm.io page: https://npm.io/package/react-router-redux-bind

## Dependencies (1)

- [history](https://npm.io/package/history.md) ^4.5.1

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.2.1 (latest) — 2017-02-13
- 0.2.0 — 2017-02-13
- 0.2.0-alpha.1 — 2017-02-13
- 0.1.9 — 2017-02-13
- 0.1.8 — 2017-02-13
- 0.1.7 — 2017-02-13
- 0.1.6 — 2017-02-12
- 0.1.5 — 2017-02-11
- 0.1.4 — 2017-02-11
- 0.1.3 — 2017-02-10
- 0.1.2 — 2017-02-10
- 0.1.1 — 2017-02-10
- 0.1.0 — 2017-02-10

## README

# react-router-redux-bind

[![Build Status](https://travis-ci.org/MaxSvargal/react-router-redux-bind.svg?branch=master)](https://travis-ci.org/MaxSvargal/react-router-redux-bind)
[![Coverage Status](https://coveralls.io/repos/github/MaxSvargal/react-router-redux-bind/badge.svg?branch=master)](https://coveralls.io/github/MaxSvargal/react-router-redux-bind?branch=master)
[![Dependencies Status](https://david-dm.org/MaxSvargal/react-router-redux-bind.svg)](https://david-dm.org/MaxSvargal/react-router-redux-bind)

Redux bindings for React Router Next v4

## Installation
`npm install --save react-router-redux-bind`


## Tutorial
A simple example of connecting to redux

```javascript
import React from 'react'
import { render } from 'react-dom'
import { createStore, applyMiddleware, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import { createBrowserHistory } from 'history'
import { Route } from 'react-router'

import {
  ConnectedRouter,
  routerMiddleware,
  routerReducer as router
} from 'react-router-redux-bind'

import reducers from './reducers'
import routes from './routes'

const history = createBrowserHistory()
const reducers = combineReducers({ ...reducers, router })
const middleware = routerMiddleware(history)
const store = createStore(reducers, applyMiddleware(middleware))

render(
  <Provider store={ store } >
    <ConnectedRouter history={ history } store={ store } routes={ routes } >
      <Route exact path="/" component={Home} />
      <Route path="/about" component={About} />
      <Route path="/topics" component={Topics} />
    </ConnectedRouter>
  </Provider>,
  document.getElementById('content')
)
```

## Actions
```javascript
import { router } from 'react-router-redux-bind'

store.dispatch(router.push('/'))
store.dispatch(router.replace({ pathname: '/foo/1', search: { from: '/' } }))
store.dispatch(router.go(-2)
store.dispatch(router.goBack()
store.dispatch(router.goForward()
```

## Routes
You can store a react-router match props through passing to `ConnectedRouter` a simple [route config](https://github.com/ReactTraining/react-router/blob/v4/packages/react-router-website/modules/examples/RouteConfig.js) looks like:

```javascript
export default [
  { path: '/', exact: true, component: require('containers/home') },
  { path: '/topics', component: require('containers/topics') }
  { path: '/topics/:id', component: require('containers/topic') }
]
```

And after action `LOCATION_CHANGE`
```javascript
store.dispatch(router.push('/topics/1'))

expect(store.getState()).toEqual({
  router: {
    location: {
      pathname: '/topics/1'
    },
    match: {
      params: {
        id: '1'
      },
      path: '/topics/:id',
      url: '/topics/1'
    }
  }
})
```

## Server side
Just use [`<StaticRouter />`](https://reacttraining.com/react-router/#staticrouter) and dispatch `setLocation` action creator, pass request url and [route config](https://github.com/ReactTraining/react-router/blob/v4/packages/react-router-website/modules/examples/RouteConfig.js).

```javascript
  const routes = require('./routes')
  const { request: { url } } = ctx // koa.js
  store.dispatch(setLocation(url, routes))
```


## Use it with [redux-saga](https://github.com/redux-saga/redux-saga)

```javascript
export function* saga() {
  while (true) {
    try {
      const { payload: { match: { path } } } = yield take(LOCATION_CHANGE)
      if (path === '/some') {
        const collection = yield call(fetchSomeCollection)
        yield put(setSomeCollection(collection))
        yield put(router.push('/another'))
      }
    } catch (err) {
      yield call(onError, err)
    }
  }
}
```

---
_Source: https://npm.io/package/react-router-redux-bind · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
