Gathering detailed insights and metrics for @banzai-inc/connected-react-router
Gathering detailed insights and metrics for @banzai-inc/connected-react-router
npm install @banzai-inc/connected-react-router
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
14,283
Last Day
29
Last Week
118
Last Month
564
Last Year
6,235
MIT License
397 Commits
6 Branches
Updated on Jun 18, 2020
Minified
Minified + Gzipped
Latest Version
6.9.7
Package Id
@banzai-inc/connected-react-router@6.9.7
Unpacked Size
436.29 kB
Size
124.72 kB
File Count
45
NPM Version
6.14.16
Node Version
12.22.12
Published on
Feb 13, 2024
Cumulative downloads
Total Downloads
Last Day
222.2%
29
Compared to previous day
Last Week
5.4%
118
Compared to previous week
Last Month
-4.4%
564
Compared to previous month
Last Year
78.6%
6,235
Compared to previous year
1
9
40
Breaking change in v5.0.0! Please read How to migrate from v4 to v5/v6.
v6.0.0 requires React v16.4.0 and React Redux v6.0 / v7.0.
A Redux binding for React Router v4 and v5
:sparkles: Synchronize router state with redux store through uni-directional flow (i.e. history -> store -> router -> components).
:gift: Supports React Router v4 and v5.
:sunny: Supports functional component hot reloading while preserving state (with react-hot-reload).
:tada: Dispatching of history methods (push
, replace
, go
, goBack
, goForward
) works for both redux-thunk and redux-saga.
:snowman: Nested children can access routing state such as the current location directly with react-redux
's connect
.
:clock9: Supports time traveling in Redux DevTools.
:gem: Supports Immutable.js
:muscle: Supports TypeScript
Connected React Router requires React 16.4 and React Redux 6.0 or later.
$ npm install --save connected-react-router
Or
$ yarn add connected-react-router
In your root reducer file,
history
as an argument and returns a root reducer.router
reducer into root reducer by passing history
to connectRouter
.router
.1// reducers.js 2import { combineReducers } from 'redux' 3import { connectRouter } from 'connected-react-router' 4 5const createRootReducer = (history) => combineReducers({ 6 router: connectRouter(history), 7 ... // rest of your reducers 8}) 9export default createRootReducer
When creating a Redux store,
history
object.history
to the root reducer creator.routerMiddleware(history)
if you want to dispatch history actions (e.g. to change URL with push('/path/to/somewhere')
).1// configureStore.js 2... 3import { createBrowserHistory } from 'history' 4import { applyMiddleware, compose, createStore } from 'redux' 5import { routerMiddleware } from 'connected-react-router' 6import createRootReducer from './reducers' 7... 8export const history = createBrowserHistory() 9 10export default function configureStore(preloadedState) { 11 const store = createStore( 12 createRootReducer(history), // root reducer with router state 13 preloadedState, 14 compose( 15 applyMiddleware( 16 routerMiddleware(history), // for dispatching history actions 17 // ... other middlewares ... 18 ), 19 ), 20 ) 21 22 return store 23}
ConnectedRouter
and pass the history
object as a prop. Remember to delete any usage of BrowserRouter
or NativeRouter
as leaving this in will cause problems synchronising the state.ConnectedRouter
as a child of react-redux
's Provider
.StaticRouter
from react-router
on the server.1// index.js 2... 3import { Provider } from 'react-redux' 4import { Route, Switch } from 'react-router' // react-router v4/v5 5import { ConnectedRouter } from 'connected-react-router' 6import configureStore, { history } from './configureStore' 7... 8const store = configureStore(/* provide initial state if any */) 9 10ReactDOM.render( 11 <Provider store={store}> 12 <ConnectedRouter history={history}> { /* place ConnectedRouter under Provider */ } 13 <> { /* your usual react-router v4/v5 routing */ } 14 <Switch> 15 <Route exact path="/" render={() => (<div>Match</div>)} /> 16 <Route render={() => (<div>Miss</div>)} /> 17 </Switch> 18 </> 19 </ConnectedRouter> 20 </Provider>, 21 document.getElementById('react-root') 22)
Note: the history
object provided to router
reducer, routerMiddleware
, and ConnectedRouter
component must be the same history
object.
Now, it's ready to work!
See the examples folder
1npm run build
Generated files will be in the lib
folder.
When testing the example apps with npm link
or yarn link
, you should explicitly provide the same Context
to both Provider
and ConnectedRouter
to make sure that the ConnectedRouter
doesn't pick up a different ReactReduxContext
from a different node_modules
folder.
In index.js
.
1... 2import { Provider, ReactReduxContext } from 'react-redux' 3... 4 <Provider store={store} context={ReactReduxContext}> 5 <App history={history} context={ReactReduxContext} /> 6 </Provider> 7...
In App.js
,
1... 2const App = ({ history, context }) => { 3 return ( 4 <ConnectedRouter history={history} context={context}> 5 { routes } 6 </ConnectedRouter> 7 ) 8} 9...
See Contributors and Acknowledge.
No vulnerabilities found.
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
119 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-03-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More