@@ -222,6 +222,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
222
222
var TransitionSuperseded = $q . reject ( new Error ( 'transition superseded' ) ) ;
223
223
var TransitionPrevented = $q . reject ( new Error ( 'transition prevented' ) ) ;
224
224
var TransitionAborted = $q . reject ( new Error ( 'transition aborted' ) ) ;
225
+ var TransitionFailed = $q . reject ( new Error ( 'transition failed' ) ) ;
225
226
226
227
root . locals = { resolve : null , globals : { $stateParams : { } } } ;
227
228
$state = {
@@ -238,7 +239,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
238
239
$state . transitionTo = function transitionTo ( to , toParams , options ) {
239
240
if ( ! isDefined ( options ) ) options = ( options === true || options === false ) ? { location : options } : { } ;
240
241
toParams = toParams || { } ;
241
- options = extend ( { location : true , inherit : false , relative : null } , options ) ;
242
+ options = extend ( { location : true , inherit : false , relative : null , $retry : false } , options ) ;
242
243
243
244
var from = $state . $current , fromParams = $state . params , fromPath = from . path ;
244
245
@@ -251,6 +252,22 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
251
252
var redirect = { to : to , toParams : toParams , options : options } ;
252
253
evt = $rootScope . $broadcast ( '$stateNotFound' , redirect , from . self , fromParams ) ;
253
254
if ( evt . defaultPrevented ) return TransitionAborted ;
255
+
256
+ // Allow the handler to return a promise to defer state lookup retry
257
+ if ( evt . retry ) {
258
+ if ( options . $retry ) return TransitionFailed ;
259
+ var retryTransition = $state . transition = $q . when ( evt . retry ) ;
260
+ retryTransition . then ( function ( ) {
261
+ if ( retryTransition !== $state . transition ) return TransitionSuperseded ;
262
+ redirect . options . $retry = true ;
263
+ return $state . transitionTo ( redirect . to , redirect . toParams , redirect . options ) ;
264
+ } ,
265
+ function ( ) {
266
+ return TransitionAborted ;
267
+ } ) ;
268
+ return retryTransition ;
269
+ }
270
+
254
271
// Always retry once if the $stateNotFound was not prevented
255
272
// (handles either redirect changed or state lazy-definition)
256
273
to = redirect . to ;
@@ -305,7 +322,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
305
322
resolved = resolveState ( state , toParams , state === to , resolved , locals ) ;
306
323
}
307
324
308
- // Once everything is resolved, wer are ready to perform the actual transition
325
+ // Once everything is resolved, we are ready to perform the actual transition
309
326
// and return a promise for the new state. We also keep track of what the
310
327
// current promise is, so that we can detect overlapping transitions and
311
328
// keep only the outcome of the last transition.
0 commit comments