title: Routes being declared in a config vs routes being declared by their controller
body: <p>I spent most of today mulling this over. There are two applications I'm working on - an ExtJS4 powered application and a Backbone powered application. In both cases they are single page apps - the user doesn't leave the page, so they can 'pause' what they're doing or looking at to react to another point of interest. </p>
  
  <p>In the ExtJS4 case, I'm using a sort of home grown route system where, when the application boots, it asks all of its controllers "What routes do you respond to?". This has, so far as I can tell, a couple of advantages - </p>
  
  <ol>
  <li>The routes are defined on the controller, so remove the controller and there's no need to update a config file.</li>
  <li>The application is easier to add controllers to, and it seems to make it much more modular.</li>
  <li>Changing routes, or parameters doesn't require the application to change, just the controller (and since the controller handles the route internally, it's very well confined).</li>
  </ol>
  
  <p>The problem is, I haven't seen any frameworks or applications so far that do something like this. I don't know why - is this such a terrible practice that it doesn't make it into a production environment? Or have I just not been working on projects that use it..? The Backbone based application is based on some crazy hackjob code, so today I rewrote most of it using the same basic format. It dropped the complexity of the code immensely, leading me to wonder if this was a 'too good to be true situation'. </p>
  
  <p>Psuedo code:</p>
  
  <pre><code>controller
      routes: ['/bookmarks', '/bookmarks/(:action)/(:id)', '/bookmarks/(:action)']
      init: fn ()
         this.application.registerRoutes(this.routes, this);
         //other code to set up views and such
      routeHandler: fn (route, params)
         //tells the application to switch the visible stuff to this thing's 
         //main view, declared elsewhere
         this.application.showView(this.view) 
         switch(params.action)
            case "edit":
               //some internal stuff to show the editing field for the ID passed..
               this.showEditor();
               this.loadRecordById(params.id)
            case "new":
               //some internal stuff 
               this.showEditor();
  </code></pre>
  
  <p>So, I guess the question is: "Is this bad practice, and why? If not, why isn't this used elsewhere? Too difficult or messy to set up with other languages? Can you foresee something coming down the pipe that will bite me later on?"</p>
  
  <p>Thanks.</p>
  
  <p>EDIT:
  I realized a few downsides last night - </p>
  
  <ol>
  <li>registering all the possible routes requires all of the controllers to start. But, even then (particularly for JS) there is an easy way around that. </li>
  <li>If I want to change a route, I've got to track down the controller that manages that particular route. Granted, that shouldn't be an issue if my routes are appropriately named. </li>
  <li>It'd be difficult to track down alias routes - i.e. /marketing_page really being /pages/3.. but this isn't how the application works, so in this case it's kind of a moot point.</li>
  </ol>