https://github.com/component/router
Simple client-side router
https://github.com/component/router
Last synced: 8 months ago
JSON representation
Simple client-side router
- Host: GitHub
- URL: https://github.com/component/router
- Owner: component
- Created: 2013-03-16T19:05:49.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-08-21T17:31:35.000Z (over 12 years ago)
- Last Synced: 2025-04-03T07:05:18.362Z (12 months ago)
- Language: JavaScript
- Size: 60.5 KB
- Stars: 31
- Watchers: 7
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# router
Simple client-side router.
## Installation
$ component install component/router
## Examples
Example with only setup callbacks:
```js
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:
```js
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:
```js
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