Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Simple client-side router
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples remove catch-all from example
test refactor
.gitignore misc
History.md Initial commit
Makefile misc
Readme.md docs
component.json refactor
index.js add examples
package.json add repository field to readme

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

Something went wrong with that request. Please try again.