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

react-router-r

v4.0.0

Published

React Router Route construction DSL

Readme

React Router R

CircleCI npm version

This library provides a declarative DSL for constructing React Router routes.

It exposes a function R, which takes:

  • 1 - a path

  • 2 - a component

  • (3...n) - optional route transformers, i.e. functions of type Route → Route

and returns a valid Route, aka a React Router plain route.


React Router R is designed for optimal readability in Coffeescript, so documentation and examples are in Coffeescript.


Example:

{R, index, child} = require 'react-router-r'

...

routes = R "/", App,
  index Landing
  child R "welcome", Landing
  child R "about", About,
    index AboutAll
    child R "foo", AboutFoo
    child R "bar", AboutBar

reduces to:

const routes = {
  path: "/",
  component: App,
  indexRoute: { component: Landing },
  childRoutes: [
    { 
      path: "welcome",
      component: Landing 
    },
    { 
      path: "about", 
      component: Landing ,
      indexRoute: { component: AboutAll },
      childRoutes: [
        { path: "foo", component: AboutFoo },
        { path: "bar", component: AboutBar }
      ]
    }
  ]
}

See ./example for the whole application.

Installation:

yarn add react-router-r

Basics:

Build a route:

R '/', App

reduces to:

{ path: "/", component: App }

Build a route with child routes:

R '/', App,
  index Landing
  child R 'welcome', Landing
  child R 'about, About

reduces to:

{
  path: "/",
  component: App,
  indexRoute: { component: Landing },
  childRoutes: [
    { path: 'welcome', component: Landing },
    { path: 'about', component: About }
  ]
}

Route Transformers:

React Router R takes and applies functions that take a React Route (as a plain route object) and returns a React Route. We call these functions route transformers. Note these transformers may mutate and return their input.

The following transformers are provided out of the box:

index

index : (component : Component) → (route : Route) → Route

Adds an indexRoute with the specified component to the route.

child

child : (childRoute : Route) → (route : Route) → Route

Adds a child route to the route.

dynamic

dynamic : ({
  path? : String,
  component? : Component,
  getRoute : (∀b. (returnRoute : ((route : Route) → b)) → b)
}) → (route : Route) → Route

Adds a child route with the optionally provided path and component with a dynamically generated grandchild route. Uses React Router's getIndexRoute and getChildRoutes under the hood.

dynamic can be used as is, but is more meant to be further abstracted upon for building application-specific dynamic route transformers. It serves as a mid-level API on top of the default low-level React Router dynamic routing API.

Write your own transfomers!

Writing route transformers is easy!

For example, let's write one that adds basic support for React Router's onEnter field:

onEnter = (onEnterCallback) -> (route) ->
  if ('onEnter' in route) throw new Error "onEnter is already defined!"
  route.onEnter = onEnterCallback
  route

Now, we can use it in our routes:


R '/', App, 
  onEnter (nextState, replace, cb) -> ...

reduces to:

{
  path: "/",
  component: App,
  onEnter: function(nextState, replace, cb) {
    ...
  }
}