title: routing backbone apps when using mediator pub/sub patterns
body: <p>I am building an application in backbone combining the modular and facade/mediator pub/sub patterns from <a href="https://github.com/addyosmani/backbone-aura/" rel="nofollow">https://github.com/addyosmani/backbone-aura/</a> to send messages between modules in order to keep a clean codebase. </p>
  
  <p>Grepping for <code>Router</code> in the entire app example for aura, I found only the readme file describing the ideal use of routers being part of modules themselves: "In Backbone.js terms, widgets are composed of Models, Views, Collections and Routers as well as any templates needed for the widget to rendered."</p>
  
  <p>So I tried a number of solutions to implement a scalable routing system (scalable meaning modules can specify their own subroutes), including a router module that accepts message <code>set-route</code> to set the route, and modules that listen to the <code>route</code> message. I've also used a sub-router per module. The problem seems that on initial page loads, because of the 'async' nature of messaging, the routes and their callbacks may not be defined by the time the global router parses the URL. You can imagine I maybe need to queue all messages before starting the router module.</p>
  
  <p>I want to implement something clean and that makes sense. I was also thinking about potentially parsing all routes of all widgets first, then instantiating the router, which makes the router module a special case, and thus, shouldn't be a part of the modules.</p>
  
  <p>Should the Router be a module that uses messages, or should it be an extension, or some higher order piece of the architecture that is global that modules do have access to? </p>
  
  <p>I know this is a loaded question, thanks in advance for any help!</p>