@@ -275,9 +275,13 @@ export class NSLocationStrategy extends LocationStrategy {
275
275
276
276
if ( ! outlet ) {
277
277
const topmostFrame = this . frameService . getFrame ( ) ;
278
- this . currentOutlet = this . getOutletByFrame ( topmostFrame ) ;
278
+ this . currentOutlet = this . getOutletByFrame ( topmostFrame ) || this . currentOutlet ;
279
+ }
280
+
281
+ const frameToBack : Frame = this . currentOutlet . getFrameToBack ( ) ;
282
+ if ( frameToBack ) {
283
+ frameToBack . goBack ( ) ;
279
284
}
280
- this . currentOutlet . getFrameToBack ( ) . goBack ( ) ;
281
285
} else {
282
286
// Nested navigation - just pop the state
283
287
if ( isLogEnabled ( ) ) {
@@ -385,10 +389,11 @@ export class NSLocationStrategy extends LocationStrategy {
385
389
routerLog ( "NSLocationStrategy._beginModalNavigation()" ) ;
386
390
}
387
391
388
- this . currentOutlet = this . getOutletByFrame ( frame ) ;
392
+ this . currentOutlet = this . getOutletByFrame ( frame ) || this . currentOutlet ;
389
393
390
394
// It is possible to have frame, but not corresponding Outlet, if
391
- // showing modal dialog on app.component.ts ngOnInit() e.g.
395
+ // showing modal dialog on app.component.ts ngOnInit() e.g. In that case
396
+ // the modal is treated as none modal navigation.
392
397
if ( this . currentOutlet ) {
393
398
this . currentOutlet . showingModal = true ;
394
399
this . _modalNavigationDepth ++ ;
@@ -400,15 +405,18 @@ export class NSLocationStrategy extends LocationStrategy {
400
405
routerLog ( "NSLocationStrategy.closeModalNavigation()" ) ;
401
406
}
402
407
403
- if ( this . _modalNavigationDepth > 0 ) {
408
+ const isShowingModal = this . _modalNavigationDepth > 0 ;
409
+
410
+ if ( isShowingModal ) {
404
411
this . _modalNavigationDepth -- ;
405
412
}
406
413
407
414
// currentOutlet should be the one that corresponds to the topmost() frame
408
415
const topmostOutlet = this . getOutletByFrame ( this . frameService . getFrame ( ) ) ;
409
- this . currentOutlet = this . findOutletByModal ( this . _modalNavigationDepth , true ) || topmostOutlet ;
416
+ const outlet = this . findOutletByModal ( this . _modalNavigationDepth , isShowingModal ) || topmostOutlet ;
410
417
411
- if ( this . currentOutlet ) {
418
+ if ( outlet ) {
419
+ this . currentOutlet = outlet ;
412
420
this . currentOutlet . showingModal = false ;
413
421
this . callPopState ( this . currentOutlet . peekState ( ) , false ) ;
414
422
}
@@ -481,7 +489,8 @@ export class NSLocationStrategy extends LocationStrategy {
481
489
this . callPopState ( null , true , currentOutlet ) ;
482
490
}
483
491
484
- if ( ! currentOutlet . isNSEmptyOutlet ) {
492
+ // Skip frames filtering since currentOutlet is <router-outlet> when no frames available.
493
+ if ( currentOutlet . frames . length && ! currentOutlet . isNSEmptyOutlet ) {
485
494
currentOutlet . frames = currentOutlet . frames . filter ( currentFrame => currentFrame !== frame ) ;
486
495
return currentOutlet . frames . length ;
487
496
}
@@ -554,26 +563,32 @@ export class NSLocationStrategy extends LocationStrategy {
554
563
return pathToOutlet || lastPath ;
555
564
}
556
565
557
- findOutletByModal ( modalNavigation : number , isShowingModal ?: boolean ) : Outlet {
558
- return this . outlets . find ( ( outlet ) => {
559
- let isEqual = outlet . modalNavigationDepth === modalNavigation ;
560
- return isShowingModal ? isEqual && outlet . showingModal : isEqual ;
561
- } ) ;
562
- }
563
-
564
566
findOutlet ( outletKey : string , activatedRouteSnapshot ?: ActivatedRouteSnapshot ) : Outlet {
565
- let outlet : Outlet = this . outlets . find ( ( currentOutlet ) => currentOutlet . outletKeys . indexOf ( outletKey ) > - 1 ) ;
567
+ let outlet : Outlet = this . outlets . find ( ( currentOutlet ) => {
568
+ let equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
569
+ return equalModalDepth && currentOutlet . outletKeys . indexOf ( outletKey ) > - 1 ;
570
+ } ) ;
566
571
567
572
// No Outlet with the given outletKey could happen when using nested unnamed p-r-o
568
573
// primary -> primary -> prymary
569
574
if ( ! outlet && activatedRouteSnapshot ) {
570
575
const pathByOutlets = this . getPathByOutlets ( activatedRouteSnapshot ) ;
571
- outlet = this . outlets . find ( ( currentOutlet ) => currentOutlet . pathByOutlets === pathByOutlets ) ;
576
+ outlet = this . outlets . find ( ( currentOutlet ) => {
577
+ let equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
578
+ return equalModalDepth && currentOutlet . pathByOutlets === pathByOutlets ;
579
+ } ) ;
572
580
}
573
581
574
582
return outlet ;
575
583
}
576
584
585
+ private findOutletByModal ( modalNavigation : number , isShowingModal ?: boolean ) : Outlet {
586
+ return this . outlets . find ( ( outlet ) => {
587
+ let equalModalDepth = outlet . modalNavigationDepth === modalNavigation ;
588
+ return isShowingModal ? equalModalDepth && outlet . showingModal : equalModalDepth ;
589
+ } ) ;
590
+ }
591
+
577
592
private getOutletByFrame ( frame : Frame ) : Outlet {
578
593
let outlet ;
579
594
0 commit comments