npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

redux-pages

v0.2.1

Published

A middleware-friendly routing helper that encapsulates raw URL paths

Downloads

39

Readme

redux-pages

A middleware-friendly routing helper that encapsulates raw URL paths.

"Parse once, route anywhere"
"Keep the state clean"

Features

  • Full control from middlewares
  • Raw URL paths is only used at definition
  • Rich template syntax

redux-pages uses @ryo33/path-template.

Diagram

Page transitions are done in the flow as shown below.

diagram.jpg

Installation

$ npm install -S redux-pages

Example

Usage

import { createStore,
  combineReducers, applyMiddleware } from 'redux'
import createHistory from 'history/createBrowserHistory'
import { createPages, createPagesReducer } from 'redux-pages'

// Define pages
const pages = createPages()
const indexPage = pages.addPage('/', 'index')
const postsPage = pages.addPage('/posts', 'posts')
const postPage = pages.addPage('/posts/:id', 'post')
const usersPage = pages.addPage('/users', 'users')
const userPage = pages.addPage('/users/:id', 'user')
const userPostPage = pages.addChildPage(
  userPage, '/posts/:number', 'userPost',
  {number: str => parseInt(str, 10)})
const errorPage = pages.addPage('/*', 'error')

const pageReducer = createPagesReducer(indexPage.name, {})
const reducer = combineReducers({
  page: pageReducer
})

const pageSelector = state => state.page

const history = createHistory()
const getCurrentPath = () => history.location.pathname
const pushPath = (path) => history.push(path)
const pagesMiddleware = pages.middleware(pageSelector, getCurrentPath, pushPath)

const store = createStore(
  reducer,
  applyMiddleware(pagesMiddleware)
)
pages.handleNavigation(store, history.location.pathname)
history.listen((location, action) => {
  pages.handleNavigation(store, location.pathname)
})

// Dispatch the action to change the page
store.dispatch(userPostPage.action({id: '5', number: 2}))
// history.location.pathname => '/users/5/posts/2'
// store.getState().page => {name: 'userPost', params: {id: '5', number: 2}}

// Change the path directly
history.push(userPage.path({id: '7'}))
// history.location.pathname => '/users/7'
// store.getState().page => {name: 'user', params: {id: '7'}}

// Go to the error page
history.push('/users/7/posts')
// history.location.pathname => '/users/7/posts'
// store.getState().page => {name: 'error', params: {}}

API

import {
  createPages,
  createPagesReducer,
  changePage,
  CHANGE_PAGE
} from 'redux-pages'

createPages() => pages

Creates a pages object.

  • pages A pages object

pages.addPage(template, name, [mapperObject]) => page

Adds a page.

  • template The URL path template Template Syntax
  • name The name of the page
  • mapperObject An object to map parsed params
    [Example]
    parsedParams: {id: '3', number: '5'}
    mapperObject: {number: str => parseInt(str, 10)}
    paramsForState: {id: '3', number: 5}
  • page A page object
    • page.name The name of the page
    • page.path([params]) Returns a path with the given params
    • page.action([params]) Returns a action with the given params
    • page.check(action) ({ type, payload }) => type === CHANGE_PAGE && payload.name === name

pages.addChildPage(page, template, name, [mapperObject]) => childPage

Adds a child page for the given page.

pages.handleNavigation(store, pathname)

Handles a navigation event.

It matches the given pathname in order of addPage/addChildPage is called.

  • store A store
  • pathname A pathname

pages.middleware(pageSelector, getCurrentPath, pushPath) => middleware

Changes the path when the middleware receives an changePage action.

  • pageSelector A selector for the page state
  • getCurrentPath A function to get the current path
  • pushPath A function to push the path

createPagesReducer([name], [params]) => reducer

Create a reducer.

The state shape is {name, params}.

  • name params The initial state

changePage(name, params) => action

Creates an action with given name and params.

  • action { type: CHANGE_PAGE, payload: {name: 'PAGE_NAME', params: PAGE_PARAMS}}

CHANGE_PAGE

The type of actions to change the page.

Author

Ryo Hashiguchi (Ryo33)

LICENSE

MIT