Skip to content

hughsk/router

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple client-side router

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%