All Projects → mksarge → Redux First Routing

mksarge / Redux First Routing

Licence: mit
A minimal, framework-agnostic API for accomplishing Redux-first routing.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Redux First Routing

Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (+27.82%)
Mutual labels:  middleware, routing
Clevergo
👅 CleverGo is a lightweight, feature rich and high performance HTTP router for Go.
Stars: ✭ 246 (+84.96%)
Mutual labels:  middleware, routing
Riptide
Client-side response routing for Spring
Stars: ✭ 169 (+27.07%)
Mutual labels:  routing, client-side
koii
A simple middleware for displaying routes in an express application
Stars: ✭ 73 (-45.11%)
Mutual labels:  middleware, routing
Swift Web
🕸 A collection of Swift server-side frameworks for handling HTML, CSS, routing and middleware.
Stars: ✭ 415 (+212.03%)
Mutual labels:  middleware, routing
Reitit
A fast data-driven router for Clojure/Script
Stars: ✭ 892 (+570.68%)
Mutual labels:  middleware, routing
Routerify
A lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.rs
Stars: ✭ 173 (+30.08%)
Mutual labels:  middleware, routing
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (+97.74%)
Mutual labels:  middleware, history
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (+109.77%)
Mutual labels:  middleware, routing
Navaid
A navigation aid (aka, router) for the browser in 850 bytes~!
Stars: ✭ 648 (+387.22%)
Mutual labels:  client-side, history
Go Bootstrap
Easy way to bootstrap a web server in Go (Routing|Middleware|Https)
Stars: ✭ 27 (-79.7%)
Mutual labels:  middleware, routing
Graphbrainz
A fully-featured GraphQL interface for the MusicBrainz API.
Stars: ✭ 130 (-2.26%)
Mutual labels:  middleware
L5 Very Basic Auth
Stateless HTTP basic auth for Laravel without the need for a database.
Stars: ✭ 127 (-4.51%)
Mutual labels:  middleware
Cookie Parser
Parse HTTP request cookies
Stars: ✭ 1,683 (+1165.41%)
Mutual labels:  middleware
Starlette Prometheus
Prometheus integration for Starlette.
Stars: ✭ 127 (-4.51%)
Mutual labels:  middleware
Express Routemap
Display all your express routes in the terminal!
Stars: ✭ 131 (-1.5%)
Mutual labels:  routing
Vpnfailsafe
IP leak prevention for OpenVPN
Stars: ✭ 130 (-2.26%)
Mutual labels:  routing
Svelte Navigator
Simple, accessible routing for Svelte
Stars: ✭ 125 (-6.02%)
Mutual labels:  routing
Bsdrp
BSD Router Project
Stars: ✭ 126 (-5.26%)
Mutual labels:  routing
Paradoxgameconverters
Various converters between different grand strategy games
Stars: ✭ 126 (-5.26%)
Mutual labels:  history

Redux-First Routing npm version build status

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.

Learn more: An Introduction to the Redux-First Routing Model

Redux-first routing

Ideology

This library wraps history and provides a minimal, framework-agnostic base for accomplishing Redux-first routing. It does not provide the actual router component.

Instead, you can pair it with a compatible router to create a complete routing solution. If you're coming from React Router, you might compare this package to react-router-redux.

Installation

Install the library from npm:

npm install --save redux-first-routing

Or, use the following script tag to access the latest UMD build on window.ReduxFirstRouting:

<script src="https://unpkg.com/redux-first-routing/dist/redux-first-routing.min.js"></script>

Usage

Basic Usage

import { combineReducers, applyMiddleware, createStore } from 'redux'
import { createBrowserHistory, routerReducer, routerMiddleware, startListener, push } from 'redux-first-routing'
import { otherReducers } from './reducers'

// Create the history object
const history = createBrowserHistory()

// Add the reducer, which adds location state to the store
const rootReducer = combineReducers({
  ...otherReducers,
  router: routerReducer // Convention is to use the "router" property
})
  
// Build the middleware, which intercepts navigation actions and calls the corresponding history method
const middleware = routerMiddleware(history)

// Create the store
const store = createStore(rootReducer, {}, applyMiddleware(middleware))

// Start the history listener, which automatically dispatches actions to keep the store in sync with the history
startListener(history, store)

// Now you can read the location from the store!
let currentLocation = store.getState().router.pathname

// You can also subscribe to changes in the location!
let unsubscribe = store.subscribe(() => {
  let previousLocation = currentLocation
  currentLocation = store.getState().router.pathname

  if (previousLocation !== currentLocation) {
    console.log(`Location changed from ${previousLocation} to ${currentLocation}`)
    // Render your application reactively here (optionally using a compatible router)
  }
})

// And you can dispatch navigation actions from anywhere!
store.dispatch(push('/about'))

State Shape

There are dozens of ways to design the state shape of the location data, and this project must by nature choose an opinionated design:

// URL: www.example.com/nested/path?with=query#and-hash
{
  router: {
    pathname: '/nested/path/',
    search: '?with=query',
    queries: {
      with: 'query'
    },
    hash: '#and-hash'
  },
  ... // other redux state
}

The query-string package is used internally to parse the search string into the queries object.

Compatible Routers

For a router to work seamlessly with redux-first-routing, it must not be tightly coupled to the browser history/navigation code. The following libraries meet that criteria by providing router components that focus solely on the routing and/or rendering part:

For examples of usage, see Recipies. To add to this list, feel free to send a pull request.

Documentation

Credits

The concept of "Redux-first routing" isn't particularly new — everything in this library has existed in one form or another across various other Redux routing libraries and packages. You may find a long list of similar projects (some of which may be classified as Redux-first routing libraries) here:

Notable influences:

Contributing

Contributions are welcome and are greatly appreciated! 🎉

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

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].