1
1
import {
2
2
Attribute , ComponentFactory , ComponentRef , Directive ,
3
- ReflectiveInjector , ResolvedReflectiveProvider , ViewContainerRef ,
3
+ ReflectiveInjector , ResolvedReflectiveProvider ,
4
+ ViewRef , ViewContainerRef ,
4
5
Inject , ComponentFactoryResolver , Injector
5
6
} from "@angular/core" ;
6
7
import { isPresent } from "../lang-facade" ;
@@ -61,6 +62,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
61
62
private viewUtil : ViewUtil ;
62
63
private refCache : RefCache = new RefCache ( ) ;
63
64
private isInitialPage : boolean = true ;
65
+ private previousPagesViews : Array < ViewRef > = new Array ( ) ;
64
66
private detachedLoaderFactory : ComponentFactory < DetachedLoader > ;
65
67
66
68
private currentActivatedComp : ComponentRef < any > ;
@@ -152,8 +154,16 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
152
154
this . currentActivatedRoute = activatedRoute ;
153
155
154
156
if ( this . locationStrategy . _isPageNavigatingBack ( ) ) {
157
+ if ( this . previousPagesViews . length ) {
158
+ this . containerRef . insert ( this . previousPagesViews . pop ( ) ) ;
159
+ }
160
+
155
161
this . activateOnGoBack ( activatedRoute , outletMap ) ;
156
162
} else {
163
+ if ( this . containerRef . length ) {
164
+ this . previousPagesViews . push ( this . containerRef . detach ( ) ) ;
165
+ }
166
+
157
167
this . activateOnGoForward ( activatedRoute , providers , outletMap , resolver , injector ) ;
158
168
}
159
169
}
@@ -176,6 +186,9 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
176
186
const inj = ReflectiveInjector . fromResolvedProviders ( providers , injector ) ;
177
187
this . currentActivatedComp = this . containerRef . createComponent (
178
188
factory , this . containerRef . length , inj , [ ] ) ;
189
+
190
+ this . currentActivatedComp . changeDetectorRef . detectChanges ( ) ;
191
+
179
192
this . refCache . push ( this . currentActivatedComp , pageRoute , outletMap , null ) ;
180
193
181
194
} else {
@@ -194,7 +207,12 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
194
207
const loaderRef = this . containerRef . createComponent (
195
208
this . detachedLoaderFactory , this . containerRef . length , childInjector , [ ] ) ;
196
209
210
+ loaderRef . changeDetectorRef . detectChanges ( ) ;
211
+
197
212
this . currentActivatedComp = loaderRef . instance . loadWithFactory ( factory ) ;
213
+
214
+ this . currentActivatedComp . changeDetectorRef . detectChanges ( ) ;
215
+
198
216
this . loadComponentInPage ( page , this . currentActivatedComp ) ;
199
217
this . refCache . push ( this . currentActivatedComp , pageRoute , outletMap , loaderRef ) ;
200
218
}
0 commit comments