Gathering detailed insights and metrics for redux-first-router
Gathering detailed insights and metrics for redux-first-router
Gathering detailed insights and metrics for redux-first-router
Gathering detailed insights and metrics for redux-first-router
npm install redux-first-router
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,564 Stars
646 Commits
142 Forks
36 Watching
26 Branches
42 Contributors
Updated on 07 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
32.8%
2,999
Compared to previous day
Last week
-1.6%
13,770
Compared to previous week
Last month
-9.8%
79,964
Compared to previous month
Last year
9.7%
803,992
Compared to previous year
2
1
35
Think of your app in terms of states, not routes or components. Connect your components and just dispatch Flux Standard Actions!
To be able to use Redux as is while keeping the address bar in sync. To define paths as actions, and handle path params and query strings as action payloads.
The address bar and Redux actions should be bi-directionally mapped, including via the browser's back/forward buttons. Dispatch an action and the address bar updates. Change the address, and an action is dispatched.
In addition, here are some obstacles Redux-First Router seeks to avoid:
react-router
and next.js
yarn add redux-first-router
(A minimal <Link>
component exists in the separate package redux-first-router-link
.)
1// configureStore.js 2import { applyMiddleware, combineReducers, compose, createStore } from 'redux' 3import { connectRoutes } from 'redux-first-router' 4 5import page from './pageReducer' 6 7const routesMap = { 8 HOME: '/', 9 USER: '/user/:id' 10} 11 12export default function configureStore(preloadedState) { 13 const { reducer, middleware, enhancer } = connectRoutes(routesMap) 14 15 const rootReducer = combineReducers({ page, location: reducer }) 16 const middlewares = applyMiddleware(middleware) 17 const enhancers = compose(enhancer, middlewares) 18 19 const store = createStore(rootReducer, preloadedState, enhancers) 20 21 return { store } 22}
1// pageReducer.js 2import { NOT_FOUND } from 'redux-first-router' 3 4const components = { 5 HOME: 'Home', 6 USER: 'User', 7 [NOT_FOUND]: 'NotFound' 8} 9 10export default (state = 'HOME', action = {}) => components[action.type] || state
1// App.js 2import React from 'react' 3import { connect } from 'react-redux' 4 5// Contains 'Home', 'User' and 'NotFound' 6import * as components from './components'; 7 8const App = ({ page }) => { 9 const Component = components[page] 10 return <Component /> 11} 12 13const mapStateToProps = ({ page }) => ({ page }) 14 15export default connect(mapStateToProps)(App)
1// components.js 2import React from 'react' 3import { connect } from 'react-redux' 4 5const Home = () => <h3>Home</h3> 6 7const User = ({ userId }) => <h3>{`User ${userId}`}</h3> 8const mapStateToProps = ({ location }) => ({ 9 userId: location.payload.id 10}) 11const ConnectedUser = connect(mapStateToProps)(User) 12 13const NotFound = () => <h3>404</h3> 14 15export { Home, ConnectedUser as User, NotFound }
connectRoutes is the primary "work" you will do to get Redux First
Router going. It's all about creating and maintaining a pairing of
action types and dynamic express style route paths. If you use our <Link />
component and pass an action as its href prop, you can change the URLs you use here any time without having to change your application code.
Besides the simple option of matching a literal path, all matching capabilities of the path-to-regexp package we use are now supported, except unnamed parameters.
One of the goals of Redux First Router is to NOT alter your actions and be 100% flux standard action-compliant. That allows for automatic support for packages such as redux-actions.
The location reducer primarily maintains the state of the current pathname and action dispatched (type + payload). That's its core mission.
A minimal link component exists in the separate package redux-first-router-link.
Queries can be dispatched by assigning a query object containing key/vals to an action, its payload object or its meta object.
Redux First Router has been thought up from the ground up with React Native (and server environments) in mind. They both make use of the history package's createMemoryHistory. In coordination, we are able to present you with a first-rate developer experience when it comes to URL-handling on native. We hope you come away feeling: "this is what I've been waiting for."
Sometimes you may want to dynamically add routes to routesMap, for example so that you can codesplit routesMap. You can do this using the addRoutes function.
Sometimes you may want to block navigation away from the current route, for example to prompt the user to save their changes.
Complete Scroll restoration and hash #links handling is addressed primarily by one of our companion packages: redux-first-router-restore-scroll (we like to save you the bytes sent to clients if you don't need it).
Ok, this is the biggest example here, but given what it does, we think it's extremely concise and sensible.
The following are features you should avoid unless you have a reason that makes sense to use them. These features revolve around the history package's API. They make the most sense in React Native--for things like back button handling.
Below are some additional methods we export. The target user is package authors. Application developers will rarely need this.
In earlier versions history was a peerDependency, this is no longer the case since version 2 has its own history management tool. This means that the arguments passed to connectRoutes(documentation) need to be changed.
You might run into a situation where you want to trigger a redirect as soon as possible in case some particular piece of state is or is not set. A possible use case could be persisting checkout state, e.g. checkoutSteps.step1Completed.
These packages attempt in similar ways to reconcile the browser history with redux actions and state.
<title>
Topics for things you can do with redux-first-router but need examples written:
state
and payload
.react-universal-component
, babel-plugin-universal-import
, webpack-flush-chunks
.Feature development efforts are occuring in the Respond framework Rudy repository.
We use commitizen, 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 will automatically be handled based on these commits thanks to [semantic-release](https:/
/github.com/semantic-release/semantic-release).
react-universal-component. Made to work perfectly with Redux-First Router.
webpack-flush-chunks. The foundation of our Universal
product line.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/13 approved changesets -- score normalized to 1
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
89 existing vulnerabilities detected
Details
Score
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