11import {
22 Attribute , ComponentFactory , ComponentRef , Directive ,
3- ReflectiveInjector , ResolvedReflectiveProvider , ViewContainerRef ,
3+ ReflectiveInjector , ResolvedReflectiveProvider ,
4+ ViewRef , ViewContainerRef ,
45 Inject , ComponentFactoryResolver , Injector
56} from "@angular/core" ;
67import { isPresent } from "../lang-facade" ;
@@ -61,6 +62,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
6162 private viewUtil : ViewUtil ;
6263 private refCache : RefCache = new RefCache ( ) ;
6364 private isInitialPage : boolean = true ;
65+ private previousPagesViews : Array < ViewRef > = new Array ( ) ;
6466 private detachedLoaderFactory : ComponentFactory < DetachedLoader > ;
6567
6668 private currentActivatedComp : ComponentRef < any > ;
@@ -152,8 +154,16 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
152154 this . currentActivatedRoute = activatedRoute ;
153155
154156 if ( this . locationStrategy . _isPageNavigatingBack ( ) ) {
157+ if ( this . previousPagesViews . length ) {
158+ this . containerRef . insert ( this . previousPagesViews . pop ( ) ) ;
159+ }
160+
155161 this . activateOnGoBack ( activatedRoute , outletMap ) ;
156162 } else {
163+ if ( this . containerRef . length ) {
164+ this . previousPagesViews . push ( this . containerRef . detach ( ) ) ;
165+ }
166+
157167 this . activateOnGoForward ( activatedRoute , providers , outletMap , resolver , injector ) ;
158168 }
159169 }
@@ -176,6 +186,9 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
176186 const inj = ReflectiveInjector . fromResolvedProviders ( providers , injector ) ;
177187 this . currentActivatedComp = this . containerRef . createComponent (
178188 factory , this . containerRef . length , inj , [ ] ) ;
189+
190+ this . currentActivatedComp . changeDetectorRef . detectChanges ( ) ;
191+
179192 this . refCache . push ( this . currentActivatedComp , pageRoute , outletMap , null ) ;
180193
181194 } else {
@@ -194,7 +207,12 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
194207 const loaderRef = this . containerRef . createComponent (
195208 this . detachedLoaderFactory , this . containerRef . length , childInjector , [ ] ) ;
196209
210+ loaderRef . changeDetectorRef . detectChanges ( ) ;
211+
197212 this . currentActivatedComp = loaderRef . instance . loadWithFactory ( factory ) ;
213+
214+ this . currentActivatedComp . changeDetectorRef . detectChanges ( ) ;
215+
198216 this . loadComponentInPage ( page , this . currentActivatedComp ) ;
199217 this . refCache . push ( this . currentActivatedComp , pageRoute , outletMap , loaderRef ) ;
200218 }
0 commit comments