1
- import { Attribute , ChangeDetectorRef , ComponentFactory , ComponentFactoryResolver , ComponentRef , Directive , Inject , InjectionToken , Injector , OnDestroy , EventEmitter , Output , Type , ViewContainerRef , ElementRef , InjectFlags , NgZone } from '@angular/core' ;
2
- import { ActivatedRoute , ActivatedRouteSnapshot , ChildrenOutletContexts , PRIMARY_OUTLET } from '@angular/router' ;
1
+ import { Attribute , ChangeDetectorRef , ComponentFactory , ComponentFactoryResolver , ComponentRef , Directive , Inject , InjectionToken , Injector , OnDestroy , EventEmitter , Output , Type , ViewContainerRef , ElementRef , InjectFlags , NgZone , EnvironmentInjector } from '@angular/core' ;
2
+ import { ActivatedRoute , ActivatedRouteSnapshot , ChildrenOutletContexts , Data , PRIMARY_OUTLET , RouterOutletContract } from '@angular/router' ;
3
3
4
4
import { Frame , Page , NavigatedData , profile , NavigationEntry } from '@nativescript/core' ;
5
5
@@ -54,7 +54,7 @@ registerElement('page-router-outlet', () => Frame);
54
54
// eslint-disable-next-line @angular-eslint/directive-selector
55
55
@Directive ( { selector : 'page-router-outlet' } ) // tslint:disable-line:directive-selector
56
56
// eslint-disable-next-line @angular-eslint/directive-class-suffix
57
- export class PageRouterOutlet implements OnDestroy {
57
+ export class PageRouterOutlet implements OnDestroy , RouterOutletContract {
58
58
// tslint:disable-line:directive-class-suffix
59
59
private activated : ComponentRef < any > | null = null ;
60
60
private _activatedRoute : ActivatedRoute | null = null ;
@@ -66,6 +66,9 @@ export class PageRouterOutlet implements OnDestroy {
66
66
private viewUtil : ViewUtil ;
67
67
private frame : Frame ;
68
68
69
+ attachEvents : EventEmitter < unknown > = new EventEmitter ( ) ;
70
+ detachEvents : EventEmitter < unknown > = new EventEmitter ( ) ;
71
+
69
72
// eslint-disable-next-line @angular-eslint/no-output-rename
70
73
@Output ( 'activate' ) activateEvents = new EventEmitter < any > ( ) ; // tslint:disable-line:no-output-rename
71
74
// eslint-disable-next-line @angular-eslint/no-output-rename
@@ -105,6 +108,13 @@ export class PageRouterOutlet implements OnDestroy {
105
108
return this . _activatedRoute ;
106
109
}
107
110
111
+ get activatedRouteData ( ) : Data {
112
+ if ( this . _activatedRoute ) {
113
+ return this . _activatedRoute . snapshot . data ;
114
+ }
115
+ return { } ;
116
+ }
117
+
108
118
constructor (
109
119
private parentContexts : ChildrenOutletContexts ,
110
120
private location : ViewContainerRef ,
@@ -222,6 +232,7 @@ export class PageRouterOutlet implements OnDestroy {
222
232
const component = this . activated ;
223
233
this . activated = null ;
224
234
this . _activatedRoute = null ;
235
+ this . detachEvents . emit ( component . instance ) ;
225
236
return component ;
226
237
}
227
238
@@ -245,6 +256,7 @@ export class PageRouterOutlet implements OnDestroy {
245
256
if ( this . isFinalPageRouterOutlet ( ) ) {
246
257
this . locationStrategy . _finishBackPageNavigation ( this . frame ) ;
247
258
}
259
+ this . attachEvents . emit ( ref . instance ) ;
248
260
}
249
261
250
262
private isFinalPageRouterOutlet ( ) {
@@ -267,7 +279,7 @@ export class PageRouterOutlet implements OnDestroy {
267
279
* This method in turn is responsible for calling the `routerOnActivate` hook of its child.
268
280
*/
269
281
@profile
270
- activateWith ( activatedRoute : ActivatedRoute , resolver : ComponentFactoryResolver | null ) : void {
282
+ activateWith ( activatedRoute : ActivatedRoute , resolver : ComponentFactoryResolver | EnvironmentInjector | null ) : void {
271
283
this . outlet = this . outlet || this . getOutlet ( activatedRoute . snapshot ) ;
272
284
if ( ! this . outlet ) {
273
285
if ( NativeScriptDebug . isLogEnabled ( ) ) {
@@ -302,12 +314,21 @@ export class PageRouterOutlet implements OnDestroy {
302
314
this . activateEvents . emit ( this . activated . instance ) ;
303
315
}
304
316
305
- private activateOnGoForward ( activatedRoute : ActivatedRoute , loadedResolver : ComponentFactoryResolver ) : void {
317
+ private activateOnGoForward ( activatedRoute : ActivatedRoute , loadedResolver : ComponentFactoryResolver | EnvironmentInjector ) : void {
306
318
if ( NativeScriptDebug . isLogEnabled ( ) ) {
307
319
NativeScriptDebug . routerLog ( 'PageRouterOutlet.activate() forward navigation - ' + 'create detached loader in the loader container' ) ;
308
320
}
309
321
310
- const factory = this . getComponentFactory ( activatedRoute , loadedResolver ) ;
322
+ let resolver : ComponentFactoryResolver ;
323
+ let ourInjector = this . location . injector ;
324
+ if ( ! ( loadedResolver instanceof ComponentFactoryResolver ) ) {
325
+ ourInjector = loadedResolver ;
326
+ resolver = loadedResolver ?. get ( ComponentFactoryResolver ) ;
327
+ } else {
328
+ resolver = loadedResolver ;
329
+ }
330
+
331
+ const factory = this . getComponentFactory ( activatedRoute , resolver ) ;
311
332
const page = this . pageFactory ( {
312
333
isNavigation : true ,
313
334
componentType : factory . componentType ,
@@ -323,7 +344,7 @@ export class PageRouterOutlet implements OnDestroy {
323
344
{ provide : ChildrenOutletContexts , useValue : this . parentContexts . getOrCreateContext ( this . name ) . children } ,
324
345
{ provide : PageService , useClass : PageService } ,
325
346
] ,
326
- parent : this . location . injector ,
347
+ parent : ourInjector ,
327
348
} ) ;
328
349
329
350
const childInjector = new DestructibleInjector ( destructables , injector ) ;
0 commit comments