packages/rebound-router/lib/rebound-router.js
function(PageApp, appName, container) {
    var oldPageName, pageInstance, routes = [];
    var isService = (container !== this.config.container);
    var name = (isService) ? appName : 'page';

    // If no container exists, throw an error
    if(!container) throw 'No container found on the page! Please specify a container that exists in your Rebound config.';

    // Add page level loading class
    container.classList.remove('error', 'loading');

    // Uninstall any old resource we have loaded
    if(!isService && this.current){ this._uninstallResource(); }

    // Load New PageApp, give it it's name so we know what css to remove when it deinitializes
    pageInstance = ComponentFactory(PageApp).el;
    if(SERVICES[name].isLazyComponent){ SERVICES[name].hydrate(pageInstance.data); }
    else{ SERVICES[name] = pageInstance.data; }
    pageInstance.__pageId = this.uid + '-' + appName;

    // Add to our page
    $(container).empty();
    container.appendChild(pageInstance);

    // Make sure we're back at the top of the page
    document.body.scrollTop = 0;

    // Add a default route handler for the route that got us here so if the component
    // does not define a route that handles it, we don't get a redirect loop
    if(!isService){ this.route(this._currentRoute, 'default', function(){ return void 0; }); }

    // Augment ApplicationRouter with new routes from PageApp added in reverse order to preserve order higherarchy
    _.each(pageInstance.data.routes, (value, key) => {
      // Add the new callback referance on to our router and add the route handler
      this.route(key, value, function () { return pageInstance.data[value].apply(pageInstance.data, arguments); });
    });

    // If this is the main page component, set it as current
    if(!isService){ this.current = pageInstance; }

    // Always return a promise
    return new Promise(function(resolve, reject){

      // Re-trigger route so the newly added route may execute if there's a route match.
      // If no routes are matched, app will hit wildCard route which will then trigger 404
      if(!isService){
        let res = Backbone.history.loadUrl(Backbone.history.fragment);
        if(res && typeof res.then === 'function') return res.then(resolve);
        return resolve(res);
      }
      // Return our newly installed app
      return resolve(pageInstance);
    });
  }
function(PageApp, appName, container) {
    var oldPageName, pageInstance, routes = [];
    var isService = (container !== this.config.container);
    var name = (isService) ? appName : 'page';

    // If no container exists, throw an error
    if(!container) throw 'No container found on the page! Please specify a container that exists in your Rebound config.';

    // Add page level loading class
    container.classList.remove('error', 'loading');

    // Uninstall any old resource we have loaded
    if(!isService && this.current){ this._uninstallResource(); }

    // Load New PageApp, give it it's name so we know what css to remove when it deinitializes
    pageInstance = ComponentFactory(PageApp).el;
    if(SERVICES[name].isLazyComponent){ SERVICES[name].hydrate(pageInstance.data); }
    else{ SERVICES[name] = pageInstance.data; }
    pageInstance.__pageId = this.uid + '-' + appName;

    // Add to our page
    $(container).empty();
    container.appendChild(pageInstance);

    // Make sure we're back at the top of the page
    document.body.scrollTop = 0;

    // Add a default route handler for the route that got us here so if the component
    // does not define a route that handles it, we don't get a redirect loop
    if(!isService){ this.route(this._currentRoute, 'default', function(){ return void 0; }); }

    // Augment ApplicationRouter with new routes from PageApp added in reverse order to preserve order higherarchy
    _.each(pageInstance.data.routes, (value, key) => {
      // Add the new callback referance on to our router and add the route handler
      this.route(key, value, function () { return pageInstance.data[value].apply(pageInstance.data, arguments); });
    });

    // If this is the main page component, set it as current
    if(!isService){ this.current = pageInstance; }

    // Always return a promise
    return new Promise(function(resolve, reject){

      // Re-trigger route so the newly added route may execute if there's a route match.
      // If no routes are matched, app will hit wildCard route which will then trigger 404
      if(!isService){
        let res = Backbone.history.loadUrl(Backbone.history.fragment);
        if(res && typeof res.then === 'function') return res.then(resolve);
        return resolve(res);
      }
      // Return our newly installed app
      return resolve(pageInstance);
    });
  }
function ( PageApp , appName , container ) { var oldPageName , pageInstance , routes = [ ] ; var isService = ( container !== this . config . container ) ; var name = ( isService ) ? appName : 'page' ; // If no container exists, throw an error if ( ! container ) throw 'No container found on the page! Please specify a container that exists in your Rebound config.' ; // Add page level loading class container . classList . remove ( 'error' , 'loading' ) ; // Uninstall any old resource we have loaded if ( ! isService && this . current ) { this . _uninstallResource ( ) ; } // Load New PageApp, give it it's name so we know what css to remove when it deinitializes pageInstance = ComponentFactory ( PageApp ) . el ; if ( SERVICES [ name ] . isLazyComponent ) { SERVICES [ name ] . hydrate ( pageInstance . data ) ; } else { SERVICES [ name ] = pageInstance . data ; } pageInstance . __pageId = this . uid + '-' + appName ; // Add to our page $ ( container ) . empty ( ) ; container . appendChild ( pageInstance ) ; // Make sure we're back at the top of the page document . body . scrollTop = 0 ; // Add a default route handler for the route that got us here so if the component // does not define a route that handles it, we don't get a redirect loop if ( ! isService ) { this . route ( this . _currentRoute , 'default' , function ( ) { return void 0 ; } ) ; } // Augment ApplicationRouter with new routes from PageApp added in reverse order to preserve order higherarchy _ . each ( pageInstance . data . routes , ( value , key ) => { // Add the new callback referance on to our router and add the route handler this . route ( key , value , function ( ) { return pageInstance . data [ value ] . apply ( pageInstance . data , arguments ) ; } ) ; } ) ; // If this is the main page component, set it as current if ( ! isService ) { this . current = pageInstance ; } // Always return a promise return new Promise ( function ( resolve , reject ) { // Re-trigger route so the newly added route may execute if there's a route match. // If no routes are matched, app will hit wildCard route which will then trigger 404 if ( ! isService ) { let res = Backbone . history . loadUrl ( Backbone . history . fragment ) ; if ( res && typeof res . then === 'function' ) return res . then ( resolve ) ; return resolve ( res ) ; } // Return our newly installed app return resolve ( pageInstance ) ; } ) ; }
Give our new page component, load routes and render a new instance of the page component in the top level outlet.
Give our new page component load routes and render a new instance of the page component in the top level outlet .