UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.registerIgnoredTransitionHook = void 0;
4var trace_1 = require("../common/trace");
5var rejectFactory_1 = require("../transition/rejectFactory");
6/**
7 * A [[TransitionHookFn]] that skips a transition if it should be ignored
8 *
9 * This hook is invoked at the end of the onBefore phase.
10 *
11 * If the transition should be ignored (because no parameter or states changed)
12 * then the transition is ignored and not processed.
13 */
14function ignoredHook(trans) {
15 var ignoredReason = trans._ignoredReason();
16 if (!ignoredReason)
17 return;
18 trace_1.trace.traceTransitionIgnored(trans);
19 var pending = trans.router.globals.transition;
20 // The user clicked a link going back to the *current state* ('A')
21 // However, there is also a pending transition in flight (to 'B')
22 // Abort the transition to 'B' because the user now wants to be back at 'A'.
23 if (ignoredReason === 'SameAsCurrent' && pending) {
24 pending.abort();
25 }
26 return rejectFactory_1.Rejection.ignored().toPromise();
27}
28exports.registerIgnoredTransitionHook = function (transitionService) {
29 return transitionService.onBefore({}, ignoredHook, { priority: -9999 });
30};
31//# sourceMappingURL=ignoredTransition.js.map
\No newline at end of file