@@ -775,7 +775,10 @@ export class NavControllerBase extends Ion implements NavController {
775
775
if ( enteringView || leavingView ) {
776
776
this . _zone . run ( ( ) => {
777
777
// Here, the order is important. WillLeave must be called before WillEnter.
778
- leavingView && this . _willLeave ( leavingView , ! enteringView ) ;
778
+ if ( leavingView ) {
779
+ const willUnload = enteringView ? leavingView . index > enteringView . index : true ;
780
+ this . _willLeave ( leavingView , willUnload ) ;
781
+ }
779
782
enteringView && this . _willEnter ( enteringView ) ;
780
783
} ) ;
781
784
}
@@ -828,6 +831,8 @@ export class NavControllerBase extends Ion implements NavController {
828
831
// ok, cleanup time!! Destroy all of the views that are
829
832
// INACTIVE and come after the active view
830
833
const activeViewIndex = this . _views . indexOf ( activeView ) ;
834
+ assert ( activeViewIndex >= 0 , 'active index is invalid' ) ;
835
+
831
836
const views = this . _views ;
832
837
let reorderZIndexes = false ;
833
838
let view : ViewController ;
@@ -1079,7 +1084,8 @@ export class NavControllerBase extends Ion implements NavController {
1079
1084
view = this . getActive ( ) ;
1080
1085
}
1081
1086
const views = this . _views ;
1082
- return views [ views . indexOf ( view ) - 1 ] ;
1087
+ const index = views . indexOf ( view ) ;
1088
+ return ( index >= 0 ) ? views [ index - 1 ] : null ;
1083
1089
}
1084
1090
1085
1091
first ( ) : ViewController {
@@ -1089,7 +1095,8 @@ export class NavControllerBase extends Ion implements NavController {
1089
1095
1090
1096
last ( ) : ViewController {
1091
1097
// returns the last page in this nav controller's stack.
1092
- return this . _views [ this . _views . length - 1 ] ;
1098
+ const views = this . _views ;
1099
+ return views [ views . length - 1 ] ;
1093
1100
}
1094
1101
1095
1102
indexOf ( view : ViewController ) : number {
@@ -1101,9 +1108,6 @@ export class NavControllerBase extends Ion implements NavController {
1101
1108
return this . _views . length ;
1102
1109
}
1103
1110
1104
- /**
1105
- * Return the stack of views in this NavController.
1106
- */
1107
1111
getViews ( ) : Array < ViewController > {
1108
1112
return this . _views ;
1109
1113
}
0 commit comments