New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redux-url

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-url

[![Build Status](https://travis-ci.org/jedirandy/redux-url.svg?branch=master)](https://travis-ci.org/jedirandy/redux-url) [![npm module](https://badge.fury.io/js/redux-url.svg)](https://www.npmjs.org/package/redux-url)

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
430
increased by36.08%
Maintainers
1
Weekly downloads
 
Created
Source

redux-url

Build Status npm module

A redux middleware that does one simple job: matches a url pattern and dispatch an action.

Install

npm install redux-url

history is needed for it to work correctly.

Usage

import createHistory from 'history/createBrowserHistory'; // choose a history implementation
import { createStore, applyMiddleware } from 'redux';
import { createRouter, navigate } from 'redux-url';

const routes = {
    '/': 'HOME', // when url is matched, will dispatch an action of type 'HOME', the payload is the matched result
    '/todos/:id': ({ id }) => ({ type: 'CHANGE_TODO', payload: id }), // you can also pass a function to custom the action, the matched result will be passed in
    '*': 'NOT_FOUND'
};

const router = createRouter(routes, createHistory());
const store = createStore(
    reducer,
    applyMiddleware(router)
);

store.dispatch(navigate(location.pathname, false)); // for state to be restored from URL when refreshed

store.dispatch(navigate('/todos/123')); // navigate to '/todos/123'

API

  • createRouter(routes, history):

    creates the middleware

    • arguments

      • routes (object) : URL patterns to be mapped, where values can be:

        • string: when matched, an action will be dispatched of which the is the given string, the payload will be the matched result

        • function: a function that takes the matched result and returns a

      • history: the history object created from lib history, such as createBrowserHistory

    • returns

      the middleware

  • navigate(path: string, replace: *boolean* = false):

    creates an action for going to the path, replace indicates whether it should modify the current history entry rather than push a new one

  • goBack():

    creates an action for going back

  • goForward():

    creates an action for going forward

  • go(n):

    creates an action for going n (can be negative) steps

Keywords

FAQs

Package last updated on 24 Feb 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc