-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathignoredTransition.ts
33 lines (27 loc) · 1.19 KB
/
ignoredTransition.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { trace } from '../common/trace.js';
import { Rejection } from '../transition/rejectFactory.js';
import { TransitionService } from '../transition/transitionService.js';
import { Transition } from '../transition/transition.js';
/**
* A [[TransitionHookFn]] that skips a transition if it should be ignored
*
* This hook is invoked at the end of the onBefore phase.
*
* If the transition should be ignored (because no parameter or states changed)
* then the transition is ignored and not processed.
*/
function ignoredHook(trans: Transition) {
const ignoredReason = trans._ignoredReason();
if (!ignoredReason) return;
trace.traceTransitionIgnored(trans);
const pending = trans.router.globals.transition;
// The user clicked a link going back to the *current state* ('A')
// However, there is also a pending transition in flight (to 'B')
// Abort the transition to 'B' because the user now wants to be back at 'A'.
if (ignoredReason === 'SameAsCurrent' && pending) {
pending.abort();
}
return Rejection.ignored().toPromise();
}
export const registerIgnoredTransitionHook = (transitionService: TransitionService) =>
transitionService.onBefore({}, ignoredHook, { priority: -9999 });