Installations
npm install connected-next-router
Developer
danielr18
Developer Guide
Module System
CommonJS, ESM
Min. Node Version
Typescript Support
Yes
Node Version
18.18.2
NPM Version
9.8.1
Statistics
109 Stars
148 Commits
30 Forks
6 Watching
16 Branches
7 Contributors
Updated on 24 Jun 2024
Languages
TypeScript (76.56%)
JavaScript (23.44%)
Total Downloads
Cumulative downloads
Total Downloads
1,365,173
Last day
-19.8%
1,542
Compared to previous day
Last week
3.5%
8,469
Compared to previous week
Last month
13.9%
34,220
Compared to previous month
Last year
-1.4%
301,061
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
4
Dev Dependencies
23
v5.0.0 requires Next.js 10 or newer, React Redux 7.1.0 or newer, and React 16.8.0 or newer. If you are using Next.js 9, check out v3 branch. If you are using Next.js 7-8, check out v0 branch.
Connected Next Router
A Redux binding for Next.js Router compatible with Next.js.
Main features
:sparkles: Keep Router state in sync with your Redux store.
:tada: Dispatch Router methods (push
, replace
, go
, goBack
, goForward
, prefetch
) using Redux actions.
:clock9: Support time traveling in Redux DevTools.
:gem: Ease migration to next.js framework from codebases using connected-react-router or react-router-redux (see migration guide).
Installation
Using npm:
$ npm install --save connected-next-router
Or yarn:
$ yarn add connected-next-router
Usage
Step 1
- Add
routerReducer
to your root reducer. - Use
createRouterMiddleware
if you want to dispatch Router actions (ex. to change URL withpush('/home')
). - Use
initialRouterState(url)
to populate router state in the server side.
1// store/configure-store.js 2import { createStore, applyMiddleware, combineReducers } from 'redux' 3import { createRouterMiddleware, initialRouterState, routerReducer } from 'connected-next-router' 4import { HYDRATE, createWrapper } from 'next-redux-wrapper' 5import Router from 'next/router' 6 7const rootReducer = combineReducers({ 8 // Add other reducers 9 router: routerReducer 10}); 11 12const routerMiddleware = createRouterMiddleware(); 13 14// Using next-redux-wrapper's initStore 15const reducer = (state, action) => { 16 if (action.type === HYDRATE) { 17 const nextState = { 18 ...state, // use previous state 19 ...action.payload, // apply delta from hydration 20 } 21 if (typeof window !== 'undefined' && state?.router) { 22 // preserve router value on client side navigation 23 nextState.router = state.router 24 } 25 return nextState 26 } else { 27 return rootReducer(state, action) 28 } 29} 30 31export const initStore = (context) => { 32 const routerMiddleware = createRouterMiddleware() 33 const { asPath } = context.ctx || Router.router || {} 34 let initialState 35 if (asPath) { 36 initialState = { 37 router: initialRouterState(asPath) 38 } 39 } 40 return createStore(reducer, initialState, applyMiddleware(routerMiddleware)) 41} 42 43export const wrapper = createWrapper(initStore)
Step 2
- Place
ConnectedRouter
as children ofreact-redux
'sProvider
.
1// pages/_app.js 2import App from 'next/app' 3import { ConnectedRouter } from 'connected-next-router' 4import { wrapper } from '../store/configure-store' 5 6class ExampleApp extends App { 7 render() { 8 const { Component, pageProps } = this.props 9 return ( 10 <ConnectedRouter> 11 <Component {...pageProps} /> 12 </ConnectedRouter> 13 ) 14 } 15} 16 17// wrapper.withRedux wraps the App with react-redux's Provider 18export default wrapper.withRedux(ExampleApp)
Examples
- examples/basic - basic reference implementation
- examples/typescript - typescript reference implementation
- without next-redux-wrapper
Acknowledgements
License
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 3/11 approved changesets -- score normalized to 2
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
- Warn: no topLevel permission defined: .github/workflows/e2e.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/e2e.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/danielr18/connected-next-router/e2e.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/e2e.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/danielr18/connected-next-router/e2e.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/e2e.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/danielr18/connected-next-router/e2e.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/e2e.yml:19
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 24 are checked with a SAST tool
Reason
61 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-7gc6-qh9x-w6h8
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-fq77-7p7r-83rj
- Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-gp95-ppv5-3jc5
- Warn: Project is vulnerable to: GHSA-54xq-cgqr-rpm3
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-wpg7-2c88-r8xv
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-fr5h-rqp8-mj6g
- Warn: Project is vulnerable to: GHSA-g77x-44xx-532m
- Warn: Project is vulnerable to: GHSA-gp8f-8m3g-qvj9
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
Score
2.7
/10
Last Scanned on 2024-11-25
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