@@ -716,7 +716,9 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
716
716
$get . $inject = [ '$rootScope' , '$q' , '$view' , '$injector' , '$resolve' , '$stateParams' , '$urlRouter' , '$location' , '$urlMatcherFactory' ] ;
717
717
function $get ( $rootScope , $q , $view , $injector , $resolve , $stateParams , $urlRouter , $location , $urlMatcherFactory ) {
718
718
719
- var TransitionSuperseded = $q . reject ( new Error ( 'transition superseded' ) ) ;
719
+ var TransitionSupersededError = new Error ( 'transition superseded' ) ;
720
+
721
+ var TransitionSuperseded = $q . reject ( TransitionSupersededError ) ;
720
722
var TransitionPrevented = $q . reject ( new Error ( 'transition prevented' ) ) ;
721
723
var TransitionAborted = $q . reject ( new Error ( 'transition aborted' ) ) ;
722
724
var TransitionFailed = $q . reject ( new Error ( 'transition failed' ) ) ;
@@ -775,7 +777,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
775
777
var retryTransition = $state . transition = $q . when ( evt . retry ) ;
776
778
777
779
retryTransition . then ( function ( ) {
778
- if ( retryTransition !== $state . transition ) return TransitionSuperseded ;
780
+ if ( retryTransition !== $state . transition ) {
781
+ $rootScope . $broadcast ( '$stateChangeCancel' , redirect . to , redirect . toParams , state , params ) ;
782
+ return TransitionSuperseded ;
783
+ }
779
784
redirect . options . $retry = true ;
780
785
return $state . transitionTo ( redirect . to , redirect . toParams , redirect . options ) ;
781
786
} , function ( ) {
@@ -1114,7 +1119,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1114
1119
var transition = $state . transition = resolved . then ( function ( ) {
1115
1120
var l , entering , exiting ;
1116
1121
1117
- if ( $state . transition !== transition ) return TransitionSuperseded ;
1122
+ if ( $state . transition !== transition ) {
1123
+ $rootScope . $broadcast ( '$stateChangeCancel' , to . self , toParams , from . self , fromParams ) ;
1124
+ return TransitionSuperseded ;
1125
+ }
1118
1126
1119
1127
// Exit 'from' states not kept
1120
1128
for ( l = fromPath . length - 1 ; l >= keep ; l -- ) {
@@ -1135,7 +1143,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1135
1143
}
1136
1144
1137
1145
// Run it again, to catch any transitions in callbacks
1138
- if ( $state . transition !== transition ) return TransitionSuperseded ;
1146
+ if ( $state . transition !== transition ) {
1147
+ $rootScope . $broadcast ( '$stateChangeCancel' , to . self , toParams , from . self , fromParams ) ;
1148
+ return TransitionSuperseded ;
1149
+ }
1139
1150
1140
1151
// Update globals in $state
1141
1152
$state . $current = to ;
@@ -1171,7 +1182,14 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1171
1182
1172
1183
return $state . current ;
1173
1184
} ) . then ( null , function ( error ) {
1174
- if ( $state . transition !== transition ) return TransitionSuperseded ;
1185
+ // propagate TransitionSuperseded error without emitting $stateChangeCancel
1186
+ // as it was already emitted in the success handler above
1187
+ if ( error === TransitionSupersededError ) return TransitionSuperseded ;
1188
+
1189
+ if ( $state . transition !== transition ) {
1190
+ $rootScope . $broadcast ( '$stateChangeCancel' , to . self , toParams , from . self , fromParams ) ;
1191
+ return TransitionSuperseded ;
1192
+ }
1175
1193
1176
1194
$state . transition = null ;
1177
1195
/**
@@ -1195,7 +1213,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1195
1213
evt = $rootScope . $broadcast ( '$stateChangeError' , to . self , toParams , from . self , fromParams , error ) ;
1196
1214
1197
1215
if ( ! evt . defaultPrevented ) {
1198
- $urlRouter . update ( ) ;
1216
+ $urlRouter . update ( ) ;
1199
1217
}
1200
1218
1201
1219
return $q . reject ( error ) ;
0 commit comments