github.com/nsqio/nsq@v1.3.0/nsqadmin/static/js/router.js (about) 1 var Backbone = require('backbone'); 2 3 var AppState = require('./app_state'); 4 var Pubsub = require('./lib/pubsub'); 5 6 7 var Router = Backbone.Router.extend({ 8 initialize: function() { 9 var bp = function(p) { 10 // remove leading slash 11 return AppState.basePath(p).substring(1); 12 }; 13 this.route(bp('/'), 'topics'); 14 this.route(bp('/topics/(:topic)(/:channel)'), 'topic'); 15 this.route(bp('/lookup'), 'lookup'); 16 this.route(bp('/nodes(/:node)'), 'nodes'); 17 this.route(bp('/counter'), 'counter'); 18 // this.listenTo(this, 'route', function(route, params) { 19 // console.log('Route: %o; params: %o', route, params); 20 // }); 21 }, 22 23 start: function() { 24 Backbone.history.start({ 25 'pushState': true 26 }); 27 }, 28 29 topics: function() { 30 Pubsub.trigger('topics:show'); 31 }, 32 33 topic: function(topic, channel) { 34 if (channel !== null) { 35 Pubsub.trigger('channel:show', topic, channel); 36 return; 37 } 38 Pubsub.trigger('topic:show', topic); 39 }, 40 41 lookup: function() { 42 Pubsub.trigger('lookup:show'); 43 }, 44 45 nodes: function(node) { 46 if (node !== null) { 47 Pubsub.trigger('node:show', node); 48 return; 49 } 50 Pubsub.trigger('nodes:show'); 51 }, 52 53 counter: function() { 54 Pubsub.trigger('counter:show'); 55 } 56 }); 57 58 59 module.exports = new Router();