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

reflex-routing

v4.3.0

Published

Routing library for JavaScript

Downloads

76

Readme

Routing

JavaScript Routing library!

Installing

To install the latest release version:

npm install --save reflex-routing

How to...?

Create a new instance of the Router object

var router = new Router;

Then add your routes!

router.add('/home', () => {
    // Do some home actions
    app.setView('home');
});

router.add('/user/:id', (id) => {
    // Do some 'profile' actions...
    app.setView('user-profile', {id});
});

To action a route

var response = router.route('/user/1');

We leave the choice of how your routes get fired to you!

More routing options

You can instantiate an instance of the Router with your routes, and you can add nested routes, too!

var router = new Router(
    {
        home: () => console.log('default'),

        about: () => console.log('about'),

        'user/:user_id': {
            edit: user_id => console.log(`editing user ${user_id}`),

            delete: user_id => console.log(`deleting user ${user_id}`)
        },

        'file/*file': file => console.log(file)
    }
);

Going somewhere? Go here instead!

New in version 4.2 is the ability to redirect to other routes, this means that if you want to avoid firing the before or after callbacks you can!

    router.redirect('/somewhere-nice');

Find and do something - but don't launch!

If for some reason you do not wish to 'fire' the route once located, pass false as the second parameter to route() e.g.

var route = router.route('/about', false);

// Do something with route here...
// Then fire the route!
route.launch();

The above functionality is essentially the same as the find() method, however, the route() method triggers the before and after callbacks.

Taking Action Prior and Post Route

Want to handle an action before or after a route is fired? Use Router.before() or Router.after() to add callbacks!

router.before((router, route, uri) => {
    if ('/old-route' == uri) {
        router.route('/replacement-route');
    }
    // do something with any of the above parameters prior to route being fired
});

router.after((router, route, uri, response) => {
    // Looks like there was no route
    if (response == null) {
        router.redirect('/');
    }
    // do something with any of the above parameters post route firing
});

Adding a new response post initialization

Want to add a callback to an existing route at any point, no problem!

// Adds an additional callback to an existing route!
router.add('user/:user_id/edit', () => console.log('another callback for this route'));

Other features

Some other features of our routing library

Wildcard Routes

Need to capture a big segment of 'stuff' but don't know what it'll look like? Use a wildcard!

// file => console.log(file) gets fired, where the parameter file 'is in/some/dir/hello.txt'
router.route('file/in/some/dir/hello.txt');

Optional Parameters

The Router supports optional parameters, e.g.

router.add('user(/:action)/:id', (action, id) => console.log(action || 'view', id));