Gathering detailed insights and metrics for connected-react-router
Gathering detailed insights and metrics for connected-react-router
Gathering detailed insights and metrics for connected-react-router
Gathering detailed insights and metrics for connected-react-router
@talend/router-bridge
Bridge on top of cmf-router or react-router v5 + connected-react-router
fusion-plugin-connected-react-router
The `fusion-plugin-connected-react-router` package provides plugin to integrate connected-react-router with your app.
connected-next-router
A Redux binding for Next.js Router
redux-first-history
Redux First History - Redux history binding support react-router - @reach/router - wouter
npm install connected-react-router
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
4,726 Stars
485 Commits
593 Forks
42 Watching
24 Branches
77 Contributors
Updated on 11 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
2.6%
72,115
Compared to previous day
Last week
6.1%
366,968
Compared to previous week
Last month
11.9%
1,492,929
Compared to previous month
Last year
-20.5%
18,883,113
Compared to previous year
5
38
2
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
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 2/5 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
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
83 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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