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

can-route-react

v0.1.2

Published

State-based routing with React components.

Readme

can-route-react

Build Status

State-based routing with React components.

What's included

can-route-react is a collection of React components that help with routing. The components are modeled after the ones found in React Router. Here's the current list of components:

  • The Route Component - Show or hide components based route data.
  • The Link Component - Create links from route state. (coming soon)

State-Based Routing

State-based routing decouples the URL from your application's routing. Routing rules and URLs are created from a state object. It's easier to change URL schemes when needed. The can-route module is arguably the best state-based router available, so it was selected for its core routing functionality.

Preparation

Before you can use the components, you'll need to setup can-route. Here's a basic example:

import route from 'can-route';
import DefineMap from 'can-define/map/map';

// Create a DefineMap to setup route attributes.
const RouteMap = DefineMap.extend({
  '*': {
    serialize: true
  },
  // Define `page` as a string type.
  page: 'string'
});
route.data = new RouteMap({});

// Create a '/page' route.
route('{page}', {page: 'home'});

route.ready();

The Route Component

The <Route> component declaratively maps routes to the component hierarchy. It basically shows/hides a component based on the route attributes you provide:

import {Route} from 'can-route-react';

// Create a basic Home component.
Home () { return (<div>Welcome Home!</div>); }

// The Home component will show when the route has a `page` attribute equal to "home".
<Route data={{page: 'home'}} component={Home} />

An alternate syntax allows you to show/hide a component based on the URL path. This is similar to React Router's Route component.

import {Route} from 'can-route-react';

// The Home component will show when the URL path is "/" or empty string.
<Route path='/' component={Home} />

Pro Tip: While the path syntax works just fine, it's not a recommended practice in state-based routing. It tightly couples your component to the URL. If you change your URL scheme, you have to fix every place that uses that URL.

Route Example

import React from 'react';
import ReactDOM from 'react-dom';
import {Route} from 'can-route-react';

// Handlers for the links
homeClicked () {
  route.data.page = 'home';
}
aboutClicked () {
  route.data.page = 'about';
}

// Components to pass into the Route component.
Home () => {
  return (<div>Welcome Home!'</div>);
};
About ({children}) => {
  return (<div>{children}</div>);
};

ReactDOM.render(
  <div className='container'>
    <div>
      <a href='javascript://' onClick={homeClicked}>Home</a>
      <a href='javascript://' onClick={aboutClicked}>About</a>
    </div>
    <div>
			{/* React Router compatible syntax is available. See Pro-tips. */}
      <Route path='/' component={Home} />
      <Route path='/about' component={About} >
        {/* This inner text will show because the About component uses `children`. */}
        Welcome to the About page!
      </Route>
    </div>
  </div>,
  document.querySelector('[root=true]')
);

Running the Demo

Do npm install or run yarn in the root directory. Start an http-server and open the root directory.

Changelog

0.1.0 - The <Route> component can render children if the routed component uses {children} in its content. 0.0.2 - Created the <Route> component.