https://github.com/zenflow/routeemitter
Isomorphic url router to (a) abstract urls as `Route`s, and (b) track and manipulate a "current" route, optionally (and by default) binding to document location on browser
https://github.com/zenflow/routeemitter
Last synced: about 1 year ago
JSON representation
Isomorphic url router to (a) abstract urls as `Route`s, and (b) track and manipulate a "current" route, optionally (and by default) binding to document location on browser
- Host: GitHub
- URL: https://github.com/zenflow/routeemitter
- Owner: zenflow
- License: mit
- Created: 2015-06-03T12:59:40.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-09T06:32:43.000Z (about 11 years ago)
- Last Synced: 2025-03-15T04:02:51.719Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://zenflow.github.io/routeemitter/
- Size: 508 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# routeemitter
Isomorphic url router to (a) abstract urls as `Route`s, and (b) track and manipulate a "current" route, optionally (and by default) binding to document location on browser
[](https://travis-ci.org/zenflow/routeemitter?branch=master)
[](https://david-dm.org/zenflow/routeemitter)
[](https://david-dm.org/zenflow/routeemitter#info=devDependencies)
[](https://www.npmjs.com/package/routeemitter)
## [documentation](https://zenflow.github.io/routeemitter/)
## installation
```
npm install --save routeemitter
```
## example
```js
var RouteEmitter = require('routeemitter');
var presenter = require('./presenter');
var api = require('./api');
var router = new RouteEmitter({
home: '/',
blog: '/blog(/tag/:tag)(/:slug)',
contact: '/contact'
}, {/* options... */});
router.on('route', function(route, old_route){
presenter.updatePage(route, old_route);
if (route.name=='blog'){
if (route.params.tag){
api.getBlogsByTag(route.params.tag).then(function(blogs){
presenter.updateBlogList(blogs);
});
}
if (route.params.slug){
api.getBlogBySlug(route.params.tag).then(function(blog){
presenter.updateCurrentBlog(blog);
});
}
}
});
```
## changelog
### 0.1.0
- Initial release as RouteEmitter