UNPKG

4.69 kBTypeScriptView Raw
1import { ComponentInstruction } from './instruction';
2/**
3 * Defines route lifecycle method `routerOnActivate`, which is called by the router at the end of a
4 * successful route navigation.
5 *
6 * For a single component's navigation, only one of either {@link OnActivate} or {@link OnReuse}
7 * will be called depending on the result of {@link CanReuse}.
8 *
9 * The `routerOnActivate` hook is called with two {@link ComponentInstruction}s as parameters, the
10 * first
11 * representing the current route being navigated to, and the second parameter representing the
12 * previous route or `null`.
13 *
14 * If `routerOnActivate` returns a promise, the route change will wait until the promise settles to
15 * instantiate and activate child components.
16 *
17 * ### Example
18 * {@example router/ts/on_activate/on_activate_example.ts region='routerOnActivate'}
19 */
20export interface OnActivate {
21 routerOnActivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any | Promise<any>;
22}
23/**
24 * Defines route lifecycle method `routerOnReuse`, which is called by the router at the end of a
25 * successful route navigation when {@link CanReuse} is implemented and returns or resolves to true.
26 *
27 * For a single component's navigation, only one of either {@link OnActivate} or {@link OnReuse}
28 * will be called, depending on the result of {@link CanReuse}.
29 *
30 * The `routerOnReuse` hook is called with two {@link ComponentInstruction}s as parameters, the
31 * first
32 * representing the current route being navigated to, and the second parameter representing the
33 * previous route or `null`.
34 *
35 * ### Example
36 * {@example router/ts/reuse/reuse_example.ts region='reuseCmp'}
37 */
38export interface OnReuse {
39 routerOnReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any | Promise<any>;
40}
41/**
42 * Defines route lifecycle method `routerOnDeactivate`, which is called by the router before
43 * destroying
44 * a component as part of a route change.
45 *
46 * The `routerOnDeactivate` hook is called with two {@link ComponentInstruction}s as parameters, the
47 * first
48 * representing the current route being navigated to, and the second parameter representing the
49 * previous route.
50 *
51 * If `routerOnDeactivate` returns a promise, the route change will wait until the promise settles.
52 *
53 * ### Example
54 * {@example router/ts/on_deactivate/on_deactivate_example.ts region='routerOnDeactivate'}
55 */
56export interface OnDeactivate {
57 routerOnDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any | Promise<any>;
58}
59/**
60 * Defines route lifecycle method `routerCanReuse`, which is called by the router to determine
61 * whether a
62 * component should be reused across routes, or whether to destroy and instantiate a new component.
63 *
64 * The `routerCanReuse` hook is called with two {@link ComponentInstruction}s as parameters, the
65 * first
66 * representing the current route being navigated to, and the second parameter representing the
67 * previous route.
68 *
69 * If `routerCanReuse` returns or resolves to `true`, the component instance will be reused and the
70 * {@link OnDeactivate} hook will be run. If `routerCanReuse` returns or resolves to `false`, a new
71 * component will be instantiated, and the existing component will be deactivated and removed as
72 * part of the navigation.
73 *
74 * If `routerCanReuse` throws or rejects, the navigation will be cancelled.
75 *
76 * ### Example
77 * {@example router/ts/reuse/reuse_example.ts region='reuseCmp'}
78 */
79export interface CanReuse {
80 routerCanReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): boolean | Promise<boolean>;
81}
82/**
83 * Defines route lifecycle method `routerCanDeactivate`, which is called by the router to determine
84 * if a component can be removed as part of a navigation.
85 *
86 * The `routerCanDeactivate` hook is called with two {@link ComponentInstruction}s as parameters,
87 * the
88 * first representing the current route being navigated to, and the second parameter
89 * representing the previous route.
90 *
91 * If `routerCanDeactivate` returns or resolves to `false`, the navigation is cancelled. If it
92 * returns or
93 * resolves to `true`, then the navigation continues, and the component will be deactivated
94 * (the {@link OnDeactivate} hook will be run) and removed.
95 *
96 * If `routerCanDeactivate` throws or rejects, the navigation is also cancelled.
97 *
98 * ### Example
99 * {@example router/ts/can_deactivate/can_deactivate_example.ts region='routerCanDeactivate'}
100 */
101export interface CanDeactivate {
102 routerCanDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): boolean | Promise<boolean>;
103}