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-simple-router

v0.1.8

Published

A simple server-side router/navigation component for ReactJS

Downloads

47

Readme

React Simple Router.

A Simple React Router that you can use on the server-side as well.

Quick Overview

  • Simple router with named router parameters.
  • Seperated Navigation handling
  • Automagic link interception
  • Only HTML5 History API support for navigation
  • Falls back to "changing the page" for legacy (no attempt to use hash/query navigation)

A Bit More Explanation

The lib is split into two parts: the Router.Component and the Router.Navigator.

The idea behind this is that we should always pass data in to our app from the top. So the only singleton is the Navigator which will only be used client-side, where a singleton is safe. On the server, navigate makes no sense and is stubbed out anyway.

The Component is a React Component used to build the structure for the app based on URL. There are no Route sub-components, you define your routes and handlers as an array of objects. The Component does not do any handling of changes to URL or provide any help to navigation.

The Navigation is a module that provide 2 functions: onNavigate which is triggered with the new path when a URL change happens and navigate used to trigger a change or URL. navigate(url, options) takes an optional options object which so far only looks for the key replace to be truthy. If options.replace is truthy then we use replaceState instead of pushState.

The Naivgation also hooks in listener to intercept link clicks and perform the navigation, so regular links Just Work™.

var React = require("react"),
    Router = require("react-simple-router");

var NotFound = React.createClass({
  render: function(){
    return React.DOM.div(null, "Page Not Found: "+this.props.path);
  }
});

var PageOne = React.createClass({
  render: function(){
    return PageAny({pageNumber: 1});
  }
});

var PageAny = React.createClass({
  render: function(){

    var anotherPage = "/page/"+Math.floor(Math.random()*1000);

    return React.DOM.div(null,
      React.DOM.h1(null, "Page "+this.props.pageNumber+"! "),
      React.DOM.p(null, React.DOM.a({href: "/not_found_here" }, "404")),
      React.DOM.p(null, React.DOM.a({href: anotherPage }, anotherPage)),
      React.DOM.p(null, React.DOM.a({href: "https://google.com"}, "external link")),
      React.DOM.p({onClick: this.programmaticNavigate, style: { "cursor": "pointer" }}, "home (n.b. this is clickable)")
    );
  },
  programmaticNavigate: function(ev){
    ev.preventDefault();
    Router.Navigator.navigate("/");
  }
});

var _routes = [
  { pattern:"/", handler: PageOne },
  { pattern:"/page/:pageNumber", handler: PageAny}
];

var App = React.createClass({
  render: function(){
    return Router.Component({
      path: this.props.path,
      routes: _routes,
      notFound: NotFound
    });
  }
});

//now the wiring.
var app = React.renderComponent(App({ path: window.location.pathname }), document.body);

// This does the event binding needed, should be set to the same as the renderComponent root node
// you can call it without a node and it will bind to `window` (normal for full page routing).
// or you can not call it at all, and it will bind to `window`.
//Router.Navigator.setAppRoot(document.body);

//add our navigation logic.
Router.Navigator.onNavigate(function(newPath){
  app.setProps({ path: newPath });
});