packages/rebound-router/lib/rebound-router.js
function(options={}, callback=function(){}) {

    // Let all of our components always have referance to our router
    Component.prototype.router = this;

    // Save our config referance
    this.config = options;
    this.config.handlers = [];
    this.config.containers = [];

    // Normalize our url configs
    this.config.root = normalizeUrl(this.config.root);
    this.config.assetRoot = this.config.assetRoot ? normalizeUrl(this.config.assetRoot) : this.config.root;
    this.config.jsPath = normalizeUrl(this.config.assetRoot, this.config.jsPath);
    this.config.cssPath = normalizeUrl(this.config.assetRoot, this.config.cssPath);

    // Get a unique instance id for this router
    this.uid = $.uniqueId('router');

    // Allow user to override error route
    this.config.errorRoute && (ERROR_ROUTE_NAME = this.config.errorRoute);

    // Convert our routeMappings to regexps and push to our handlers
    _.each(this.config.routeMapping, function(value, route){
      var regex = this._routeToRegExp(route);
      this.config.handlers.unshift({ route: route, regex: regex, app: value });
    }, this);

    // Use the user provided container, or default to the closest `<main>` tag
    this.config.container = $((this.config.container || 'main'))[0];
    this.config.containers.push(this.config.container);
    SERVICES.page = new ServiceLoader('page');

    // Install our global components
    _.each(this.config.services, function(selector, route){
      var container = $(selector)[0] || document.createElement('span');
      this.config.containers.push(container);
      SERVICES[route] = new ServiceLoader(route);
      this._fetchResource(route, container).catch(function(){});
    }, this);

    // Watch click events on links in all out containers
    this._watchLinks(this.config.containers);

    // Start the history and call the provided callback
    Backbone.history.start({
      pushState: (this.config.pushState === undefined) ? true : this.config.pushState,
      root: (this.config.root || '')
    }).then(callback);

    return this;
  }
function(options={}, callback=function(){}) {

    // Let all of our components always have referance to our router
    Component.prototype.router = this;

    // Save our config referance
    this.config = options;
    this.config.handlers = [];
    this.config.containers = [];

    // Normalize our url configs
    this.config.root = normalizeUrl(this.config.root);
    this.config.assetRoot = this.config.assetRoot ? normalizeUrl(this.config.assetRoot) : this.config.root;
    this.config.jsPath = normalizeUrl(this.config.assetRoot, this.config.jsPath);
    this.config.cssPath = normalizeUrl(this.config.assetRoot, this.config.cssPath);

    // Get a unique instance id for this router
    this.uid = $.uniqueId('router');

    // Allow user to override error route
    this.config.errorRoute && (ERROR_ROUTE_NAME = this.config.errorRoute);

    // Convert our routeMappings to regexps and push to our handlers
    _.each(this.config.routeMapping, function(value, route){
      var regex = this._routeToRegExp(route);
      this.config.handlers.unshift({ route: route, regex: regex, app: value });
    }, this);

    // Use the user provided container, or default to the closest `<main>` tag
    this.config.container = $((this.config.container || 'main'))[0];
    this.config.containers.push(this.config.container);
    SERVICES.page = new ServiceLoader('page');

    // Install our global components
    _.each(this.config.services, function(selector, route){
      var container = $(selector)[0] || document.createElement('span');
      this.config.containers.push(container);
      SERVICES[route] = new ServiceLoader(route);
      this._fetchResource(route, container).catch(function(){});
    }, this);

    // Watch click events on links in all out containers
    this._watchLinks(this.config.containers);

    // Start the history and call the provided callback
    Backbone.history.start({
      pushState: (this.config.pushState === undefined) ? true : this.config.pushState,
      root: (this.config.root || '')
    }).then(callback);

    return this;
  }
function ( options = { } , callback = function ( ) { } ) { // Let all of our components always have referance to our router Component . prototype . router = this ; // Save our config referance this . config = options ; this . config . handlers = [ ] ; this . config . containers = [ ] ; // Normalize our url configs this . config . root = normalizeUrl ( this . config . root ) ; this . config . assetRoot = this . config . assetRoot ? normalizeUrl ( this . config . assetRoot ) : this . config . root ; this . config . jsPath = normalizeUrl ( this . config . assetRoot , this . config . jsPath ) ; this . config . cssPath = normalizeUrl ( this . config . assetRoot , this . config . cssPath ) ; // Get a unique instance id for this router this . uid = $ . uniqueId ( 'router' ) ; // Allow user to override error route this . config . errorRoute && ( ERROR_ROUTE_NAME = this . config . errorRoute ) ; // Convert our routeMappings to regexps and push to our handlers _ . each ( this . config . routeMapping , function ( value , route ) { var regex = this . _routeToRegExp ( route ) ; this . config . handlers . unshift ( { route : route , regex : regex , app : value } ) ; } , this ) ; // Use the user provided container, or default to the closest `<main>` tag this . config . container = $ ( ( this . config . container || 'main' ) ) [ 0 ] ; this . config . containers . push ( this . config . container ) ; SERVICES . page = new ServiceLoader ( 'page' ) ; // Install our global components _ . each ( this . config . services , function ( selector , route ) { var container = $ ( selector ) [ 0 ] || document . createElement ( 'span' ) ; this . config . containers . push ( container ) ; SERVICES [ route ] = new ServiceLoader ( route ) ; this . _fetchResource ( route , container ) . catch ( function ( ) { } ) ; } , this ) ; // Watch click events on links in all out containers this . _watchLinks ( this . config . containers ) ; // Start the history and call the provided callback Backbone . history . start ( { pushState : ( this . config . pushState === undefined ) ? true : this . config . pushState , root : ( this . config . root || '' ) } ) . then ( callback ) ; return this ; }
On startup, save our config object and start the router
On startup save our config object and start the router