@@ -368,14 +368,13 @@ export class Transition implements IHookRegistry {
368
368
}
369
369
370
370
/**
371
- * If the current transition is a redirect, returns the transition that was redirected.
372
- *
373
371
* Gets the transition from which this transition was redirected.
374
372
*
373
+ * If the current transition is a redirect, this method returns the transition that was redirected.
375
374
*
376
375
* #### Example:
377
376
* ```js
378
- * let transitionA = $state.go('A').transitionA
377
+ * let transitionA = $state.go('A').transition
379
378
* transitionA.onStart({}, () => $state.target('B'));
380
379
* $transitions.onSuccess({ to: 'B' }, (trans) => {
381
380
* trans.to().name === 'B'; // true
@@ -389,6 +388,37 @@ export class Transition implements IHookRegistry {
389
388
return this . _options . redirectedFrom || null ;
390
389
}
391
390
391
+ /**
392
+ * Gets the original transition in a redirect chain
393
+ *
394
+ * A transition might belong to a long chain of multiple redirects.
395
+ * This method walks the [[redirectedFrom]] chain back to the original (first) transition in the chain.
396
+ *
397
+ * #### Example:
398
+ * ```js
399
+ * // states
400
+ * registry.register({ name: 'A', redirectTo: 'B' });
401
+ * registry.register({ name: 'B', redirectTo: 'C' });
402
+ * registry.register({ name: 'C', redirectTo: 'D' });
403
+ * registry.register({ name: 'D' });
404
+ *
405
+ * let transitionA = $state.go('A').transition
406
+ *
407
+ * $transitions.onSuccess({ to: 'D' }, (trans) => {
408
+ * trans.to().name === 'D'; // true
409
+ * trans.redirectedFrom().to().name === 'C'; // true
410
+ * trans.originalTransition() === transitionA; // true
411
+ * trans.originalTransition().to().name === 'A'; // true
412
+ * });
413
+ * ```
414
+ *
415
+ * @returns The original Transition that started a redirect chain
416
+ */
417
+ originalTransition ( ) : Transition {
418
+ let rf = this . redirectedFrom ( ) ;
419
+ return ( rf && rf . originalTransition ( ) ) || this ;
420
+ }
421
+
392
422
/**
393
423
* Get the transition options
394
424
*
0 commit comments