A nice client-side router.
$ component install ianstormtaylor/router
var Router = require('router');
var router = new Router()
.on('/about/:user', user)
.on('/about/:user/:section', user, load)
.listen('/about');
function user (context, next) {
console.log(context.params.user); // 'ian'
context.thing = 1;
next();
}
function load (context, next) {
var p = context.params;
console.log(p.user); // 'ian'
console.log(p.section); // 'bio'
console.log(context.thing); // 1
next();
}
router.go('/about/ian/bio');Bind middleware functions to a path. Middleware take next callbacks to move to the next middleware on the queue.
Trigger middleware for a path.
Push a path onto the history.
Replace the current URL in the history with a new path.
Dispatch to a path or the current URL. If a path is passed, it will be pushed onto the history.
Start listening for link clicks that the router should handle, optionally namespaced by a path.
Use the given plugin.
MIT