Installations
npm install redux-first-router-link
Developer
faceyspacey
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
11.6.0
NPM Version
6.5.0
Statistics
56 Stars
101 Commits
33 Forks
5 Watching
31 Branches
12 Contributors
Updated on 07 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
3,949,524
Last day
8.8%
1,747
Compared to previous day
Last week
12%
8,907
Compared to previous week
Last month
-20%
39,350
Compared to previous month
Last year
-10.3%
579,256
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
Peer Dependencies
4
Dev Dependencies
32
redux-first-router-link
UPDATE (July 1st 2017): We now have a
NavLink
package like react-router to show active styles for your links.
Installation
1yarn add redux-first-router-link
Usage
1import Link from 'redux-first-router-link' 2 3// as a standard href path string: 4<Link to='/list/db-graphql'>DB & GRAPHQL</Link> 5 6// as an array of path segments: 7<Link to={['list', 'react-redux']}>REACT & REDUX</Link> 8 9// as an action object (RECOMMENDED APPROACH SO YOU CAN CHANGE ALL URLs FROM YOUR ROUTESMAP): 10<Link to={{ type: 'LIST', payload: { category: 'fp' } }}>FP</Link>
In all 3 cases, a simple link will be rendered, eg:
1<a to='/list/fp'>FP</a>
NavLink:
1import { NavLink } from 'redux-first-router-link' 2 3<NavLink 4 to={{ type: 'LIST', payload: { category: 'redux-first-router' } }} 5 activeClassName='active' 6 activeStyle={{ color: 'purple' }} 7 exact={true} 8 strict={true} 9 isActive={(match, location) => location.payload.category === 'redux-first-router'} 10> 11 Redux First Router 12</NavLink>
NOTE: both
<Link />
and<NavLink />
share the React Router API for easy use for those coming from there. Our components are a subset of React Router's Link component props API as there are several additional props. See below.
Recommendation
Creating your links using an action
object is obviously the best solution, as it will allow you to change
static path segments in the routesMap
you pass to connectRoutes()
at any time, without
having to change any of your <Link />
components. That means you only have to change URLs in one place. AKA, your routesMap
is your "single source of truth."
For example, if you have:
1import { createStore, compose, applyMiddleware, combineReducers } from 'redux' 2import createBrowserHistory from 'history/createBrowserHistory' 3import connectRoutes from 'redux-first-router' 4 5const history = createBrowserHistory() 6 7const { enhancer, middleware, reducer } = connectRoutes(history, { 8 LIST: '/list/:category' 9}) 10 11const rootReducer = combineReducers({ location: reducer }) 12const store = createStore(rootReducer, compose(enhancer, applyMiddleware(middleware)))
Then you can change the static segment of the path at any time, eg:
1const { middleware, enhancer, reducer } = connectRoutes(history, { 2 LIST: '/browse/:category' 3})
But its entirely up to you. If it's easier to start to thinking in terms of paths, go for it! If that's the case, we recommend the array syntax, since its easier to pass variables, eg:
1const category = 'react-redux' 2const to = ['list', category] 3<Link to={to}>REACT & REDUX</Link>
vs
1const category = 'react-redux' 2const to = `/list/${category}` // can get long & yucky with lots of variables 3<Link to={to}>REACT & REDUX</Link>
Additional Props:
- down: boolean = false - if
true
supplied, will trigger linking/dispatchingonMouseDown
instead ofonMouseUp
. - shouldDispatch: boolean = true - if
false
will not dispatch (useful for SEO when action handled in a parent or child element in a fancy way) - target: string - eg:
'_blank'
to open up URL in a new tab (same as standardtarget
attribute to<a>
tags) - ...props: - you can pass any additional props that an
<a>
tag takes, such asclassName
andstyle
.
Familiar React Router Props:
- redirect: boolean = false - if
true
supplied, will dispatching your action as a redirect, resulting in the current page in the browser history being replaced rather than pushed. That means if the user presses the browser BACK button, he/she won't be able to go back to the previous page that had the link--he/she will go to the page before that. alias: replace - onClick: (SyntheticEvent) => ?boolean - you can provide an
onClick
handler to do anything you want (e.g. play a sound), but if you returnfalse
or callevent.preventDefault()
it will prevent linking/dispatching just as you may be used to. TIP: use either instead ofshouldDispatch
when you want to dynamically determine whether to trigger the action or not!
React Router NavLink
-only Props
- activeClassName: string - the class applied when the URL and
to
path match - activeStyle: object - the style object applied when the URL and
to
path match - exact: boolean = false - if
true
supplied, active class/styles will not be applied in this example: URL is/foo/bar
and linkto
is/foo
. Whereas by default they would match. - strict: boolean = false - if there is a trailing slash in the
to
path or URL, they both must have the slash to match. If there is no slash, they must both have no slash. - isActive: (match, location) => boolean - a custom function to determine whether the link is active. Return
true
if active. Thematch
argument is identical to React Router and not very useful. Thelocation
isstate.location
. - ariaCurrent: string - defaults to
'true'
when active. It's for screen-readers. Learn more here.
Final Notes
-
In previous versions the
to
prop was namedhref
and theonClick
prop was nameonPress
. Those still work, but they are identical to their new names. They will be removed eventually. -
redirect
hasreplace
as an alias for easy migration from React Router, but the terminology in our system isredirect
. You won't here the wordreplace
much, even though that's what happens to the browser history. The reason is because server-side redirects is central to the problem solved as well, not just client-side history replacement. In general, it's a more descriptive term for how the system responds to it.
Contributing
We use commitizen, so run npm run cm
to make commits. A command-line form will appear, requiring you answer a few questions to automatically produce a nicely formatted commit. Releases, semantic version numbers, tags, changelogs and publishing to NPM will automatically be handled based on these commits thanks to semantic-release. Be good.
Tests
Reviewing a package's tests are a great way to get familiar with it. It's direct insight into the capabilities of the given package (if the tests are thorough). What's even better is a screenshot of the tests neatly organized and grouped (you know the whole "a picture says a thousand words" thing).
Below is a screenshot of this module's tests running in Wallaby ("An Integrated Continuous Testing Tool for JavaScript") which everyone in the React community should be using. It's fantastic and has taken my entire workflow to the next level. It re-runs your tests on every change along with comprehensive logging, bi-directional linking to your IDE, in-line code coverage indicators, and even snapshot comparisons + updates for Jest! I requestsed that feature by the way :). It's basically a substitute for live-coding that inspires you to test along your journey.
No vulnerabilities found.
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 10/19 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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 25 are checked with a SAST tool
Reason
92 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-4x6g-3cmx-w76r
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-9j49-mfvp-vmhm
- 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-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-8g7p-74h8-hg48
- Warn: Project is vulnerable to: GHSA-pc5p-h8pf-mvwp
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q
- Warn: Project is vulnerable to: GHSA-jg8v-48h5-wgxg
- Warn: Project is vulnerable to: GHSA-36fh-84j7-cv5h
- 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-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-4c7m-wxvm-r7gc / GHSA-pch5-whg9-qr2r
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-q674-xm3x-2926
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-r2j6-p67h-q639
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-hpqj-7cj6-hfj8
- Warn: Project is vulnerable to: GHSA-4vrv-93c7-m92j
- Warn: Project is vulnerable to: GHSA-qqqw-gm93-qf6m
- Warn: Project is vulnerable to: GHSA-69f9-h8f9-7vjf
- Warn: Project is vulnerable to: GHSA-652h-xwhf-q4h6
- 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-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-xc7v-wxcw-j472
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.4
/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