routeemitter

0.1.0-rc3 • Public • Published

routeemitter

Isomorphic url router to (a) abstract urls as Routes, and (b) track and manipulate a "current" route, optionally (and by default) binding to document location on browser

build status dependencies dev-dependencies

npm

documentation

installation

npm install --save routeemitter

example

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

Package Sidebar

Install

npm i routeemitter

Weekly Downloads

2

Version

0.1.0-rc3

License

MIT

Last publish

Collaborators

  • zen_flow