 extractParamNamesRe = /:(\w+)/g
 firstRender = true
 
-module.exports = class Router extends Backbone.Router
+module.exports = class Router
 
   currentFragment: null
   previousFragment: null
 
+  # Internally stored route definitions.
+  _routes: null
+
+  # Instance of Backbone.Router used to manage browser history.
+  _router: null
+
+  constructor: (options) ->
+    @_routes = []
+    @_router = new Backbone.Router
+    @initialize(options)
+
   initialize: (options) ->
     @app = options.app
-    @initRoutes()
+
+    @buildRoutes()
+
     @on 'action:start', @trackAction
     @app.on 'reload', @renderView
 


  getController: (controller) ->
    require("controllers/#{controller}_controller")

  getParamsHash: (pattern, paramsArray) ->
    paramNames = _.map(pattern.match(extractParamNamesRe), (name) -> name.slice(1))

    if not _.isFunction(View)
      throw new Error("View '#{key}' not found.")
    View

# Mix in Backbone.Events.
# TODO: Should this be EventEmitter instead?
_.extend module.exports.prototype, Backbone.Events
