Skip to content

Commit 876ae3a

Browse files
committed
document all the hooks!
1 parent 0f323d9 commit 876ae3a

File tree

6 files changed

+122
-1
lines changed

6 files changed

+122
-1
lines changed

docs/pipeline/activate.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# `activate(transition) [-> Promise]`
2+
3+
Called on an incoming component during the activation phase when it is created and about to get transitioned in.
4+
5+
### Arguments
6+
7+
- `transition`
8+
9+
Call `transition.next()` to resolve the hook. Note calling `transition.abort()` here will not take the app back to the previous route because the transition has already been validated.
10+
11+
### Return Value
12+
13+
- Optionally return a Promise.
14+
- `resolve` -> `transition.next()`
15+
- `reject(reason)` -> `transition.abort(reason)`
16+
17+
### Details
18+
19+
In most cases this hook is used to control the timing of the view switching, because the view switching will not happen until this hook is resolved.
20+
21+
This hook is called top-down. A child view's `activate` will only get called when its parent view's `activate` has been resolved.

docs/pipeline/can-activate.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# `canActivate(transition) [-> Promise | Boolean]`
2+
3+
Called on an incoming component during the validation phase.
4+
5+
### Arguments
6+
7+
- `transition`
8+
9+
Call `transition.next()` to resolve the hook. Calling `transition.abort()` will invalidate and cancel the transition.
10+
11+
### Return Value
12+
13+
- Optionally return a Promise:
14+
15+
- `resolve(true)` -> `transition.next()`
16+
- `resolve(false)` -> `transition.abort()`
17+
- `reject(reason)` -> `transition.abort(reason)`
18+
19+
- Optionally return a Boolean:
20+
21+
- `true` -> `transition.next()`
22+
- `false` -> `transition.abort()`
23+
24+
### Details
25+
26+
This hook is called top-down. A child view's `canActivate` will only get called when its parent view's `canActivate` has been resolved.

docs/pipeline/can-deactivate.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# `canDeactivate(transition) [-> Promise | Boolean]`
2+
3+
Called on a leaving component during the validation phase.
4+
5+
### Arguments
6+
7+
- `transition`
8+
9+
Call `transition.next()` to resolve the hook. Calling `transition.abort()` will invalidate and cancel the transition.
10+
11+
### Return Value
12+
13+
- Optionally return a Promise:
14+
15+
- `resolve(true)` -> `transition.next()`
16+
- `resolve(false)` -> `transition.abort()`
17+
- `reject(reason)` -> `transition.abort(reason)`
18+
19+
- Optionally return a Boolean:
20+
21+
- `true` -> `transition.next()`
22+
- `false` -> `transition.abort()`
23+
24+
### Details
25+
26+
This hook is called from bottom-up. A parent view component's `canDeactivate` only gets called when its child's `canDeactivate` has resolved.

docs/pipeline/can-reuse.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# `canReuse {Boolean} | canReuse(transition) -> Boolean`
2+
3+
Determines whether a component can be reused. If a component cannot be reused, the current instance will be replaced by a new one and it will go through the normal validation and activation phase.
4+
5+
This route options can either be a plain Boolean value, or a function that synchronously returns a Boolean. **Defaults to `true`**.
6+
7+
### Arguments
8+
9+
- `transition`
10+
11+
You can only access `transition.to` and `transition.from` in a `canReuse` hook.
12+
13+
### Return Value
14+
15+
- Must return a Boolean. Falsy values are treated as `false`.
16+
17+
### Details
18+
19+
`canReuse` is called synchronously, top-down for all potentially reusable components.
20+
21+
If a component is reused, its `data` hook will still get called during the activation phase.

docs/pipeline/data.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `data(transition) [-> Promise]`
22

3+
Called on an incoming component during the activation phase, after the `activation` hook has been resolved. Load and set data on the current component.
4+
35
### Arguments
46

57
- `transition`
@@ -8,7 +10,9 @@
810

911
### Return Value
1012

11-
- optionally return a Promise that resolves to the data to be set on the component.
13+
- optionally return a Promise.
14+
- `resolve(data)` -> `transition.next(data)`
15+
- `reject(reason)` -> `transition.abort(reason)`
1216

1317
### Details
1418

@@ -28,6 +32,8 @@ The `data` hook is different from `activate` in that:
2832

2933
- Instead, we can react to user input instantly and start switching the view, while displaying the new component with a "loading" state. If we have a CSS transition in between, the animation time can overlap nicely with the data wait time.
3034

35+
With that said, if you still wish to wait until data is loaded before switching the view, you can add **`waitForData: true`** inside your component's `route` option.
36+
3137
### Examples
3238

3339
By calling `transition.next`:

docs/pipeline/deactivate.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# `deactivate(transition) [-> Promise]`
2+
3+
Called on a leaving component the activation phase when it is about to be deactivated and removed.
4+
5+
### Arguments
6+
7+
- `transition`
8+
9+
Call `transition.next()` to resolve the hook. Note calling `transition.abort()` here will not take the app back to the previous route because the transition has already been validated.
10+
11+
### Return Value
12+
13+
- Optionally return a Promise.
14+
- `resolve` -> `transition.next()`
15+
- `reject(reason)` -> `transition.abort(reason)`
16+
17+
### Details
18+
19+
This hook is called from bottom-up. A parent view component's `deactivate` only gets called when its child's `deactivate` has resolved.
20+
21+
New components' `activate` hooks will only get called when all current components' `deactivate` hooks have been resolved.

0 commit comments

Comments
 (0)