Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/component/router
Simple client-side router
https://github.com/component/router
Last synced: 12 days ago
JSON representation
Simple client-side router
- Host: GitHub
- URL: https://github.com/component/router
- Owner: component
- Created: 2013-03-16T19:05:49.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-08-21T17:31:35.000Z (over 11 years ago)
- Last Synced: 2024-05-08T17:07:09.246Z (8 months ago)
- Language: JavaScript
- Size: 60.5 KB
- Stars: 31
- Watchers: 8
- 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