Simple client-side router
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
test refactor Mar 16, 2013
.gitignore misc Mar 16, 2013
History.md Initial commit Mar 16, 2013
Makefile
Readme.md
component.json
index.js add examples Mar 16, 2013
package.json add repository field to readme Aug 21, 2013

Readme.md

router

Simple client-side router.

Installation

$ component install component/router

Examples

Example with only setup callbacks:

var Router = require('router');

var router = new Router;

router.get('/user/:id', function(id){
  console.log('show %s', id);
});

router.dispatch('/user/2');

Setup and teardown callbacks for unbinding events etc:

var Router = require('router');

var router = new Router;

router.get('/user/:id', function(id){
  console.log('show %s', id);
}, function(id){
  console.log('hide %s', id);
});

router.dispatch('/user/2');
router.dispatch('/user/5');
router.dispatch('/user/10');

Fluent api equivalent of above:

var Router = require('router');

var router = new Router;

router.get('/user/:id')
.before(function(id){
  console.log('show %s', id);
})
.after(function(id){
  console.log('hide %s', id);
});

router.dispatch('/user/2');
router.dispatch('/user/5');
router.dispatch('/user/10');

License

MIT