Socket
Socket
Sign inDemoInstall

redux-first-routing

Package Overview
Dependencies
2
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    redux-first-routing

Redux-first routing


Version published
Weekly downloads
264
decreased by-2.94%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Redux-First Routing

Achieve client-side routing the Redux way:

  • Read location data from the store.
  • Update the location by dispatching navigation actions.
  • Let middleware handle the side-effect of history navigation.

Redux-first routing

Ideology

This library wraps history and provides a framework-agnostic base for accomplishing Redux-first routing. For a complete routing solution, pair it with a compatible client-side routing library (see Recipies for examples).

Recipies

API

State Shape

There are dozens of ways to design the state shape of the location data, and this project by nature must choose a single, opinonated implementation. Here is the current design:

{
  ..., // other redux state 
  location: {
    pathname: '/nested/path/',
    search: '?with=query',
    queries: {
      with: 'query',
    },
    hash: '#and-hash'
  }
}
// current location: 'www.website.com/nested/path?with=query#and-hash'
Exports

Here's a look at the exports in src/index.js:

// History API
export { createBrowserHistory } from 'history/createBrowserHistory';
export { startListener } from './listener';

// Redux API
export { PUSH, REPLACE, GO, GO_BACK, GO_FORWARD, LOCATION_CHANGE } from './constants';
export { push, replace, go, goBack, goForward, locationChange } from './actions';
export { routerMiddleware } from './middleware';
export { routerReducer } from './reducer';
  • Redux API
    • push(), replace(), go(), goBack(), goForward()
      • Public action creators used to update the location.
      • Use these navigation actions instead of calling the history navigation methods directly!
    • PUSH, REPLACE, GO, GO_BACK, GO_FORWARD
      • Public action types for use in user-defined middleware.
    • routerMiddleware(history)
      • Intercepts the navigation actions to update the browser history.
    • routerReducer
      • Adds the location data (pathname, search, hash) to the state tree upon receiving a LOCATION_CHANGE action.
  • History API
    • createBrowserHistory()
      • Creates a history object.
    • startListener(history, store)
      • Creates a history listener that responds to the middleware and external navigation by dispatching a locationChange action.

Contributing

Contributions are welcome and are greatly appreciated! :tada:

Feel free to file an issue, start a discussion, or send a pull request.

License

MIT

Keywords

FAQs

Last updated on 04 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc