@@ -222,6 +222,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
222222 var TransitionSuperseded = $q . reject ( new Error ( 'transition superseded' ) ) ;
223223 var TransitionPrevented = $q . reject ( new Error ( 'transition prevented' ) ) ;
224224 var TransitionAborted = $q . reject ( new Error ( 'transition aborted' ) ) ;
225+ var TransitionFailed = $q . reject ( new Error ( 'transition failed' ) ) ;
225226
226227 root . locals = { resolve : null , globals : { $stateParams : { } } } ;
227228 $state = {
@@ -238,7 +239,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
238239 $state . transitionTo = function transitionTo ( to , toParams , options ) {
239240 if ( ! isDefined ( options ) ) options = ( options === true || options === false ) ? { location : options } : { } ;
240241 toParams = toParams || { } ;
241- options = extend ( { location : true , inherit : false , relative : null } , options ) ;
242+ options = extend ( { location : true , inherit : false , relative : null , $retry : false } , options ) ;
242243
243244 var from = $state . $current , fromParams = $state . params , fromPath = from . path ;
244245
@@ -251,6 +252,22 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
251252 var redirect = { to : to , toParams : toParams , options : options } ;
252253 evt = $rootScope . $broadcast ( '$stateNotFound' , redirect , from . self , fromParams ) ;
253254 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+
254271 // Always retry once if the $stateNotFound was not prevented
255272 // (handles either redirect changed or state lazy-definition)
256273 to = redirect . to ;
@@ -305,7 +322,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
305322 resolved = resolveState ( state , toParams , state === to , resolved , locals ) ;
306323 }
307324
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
309326 // and return a promise for the new state. We also keep track of what the
310327 // current promise is, so that we can detect overlapping transitions and
311328 // keep only the outcome of the last transition.
0 commit comments