Overview
Transition hooks allow you to tap into the transition lifecycle. Hooks are registered with match criteria to control when they fire, and can return values to control transition behavior.HookMatchCriteria
Defines which transitions should invoke a hook.true (match all).
HookMatchCriterion
Each criterion can be:- String - Glob pattern matching state name
- Boolean -
truematches all,falsematches none - Function - Custom predicate:
(state, transition) => boolean
Match Criteria Examples
Basic State Matching
Glob Patterns
Multiple Criteria
Function Predicates
Entering/Exiting/Retained
Complex Example
HookRegOptions
Options for configuring hook registration.priority
Controls hook execution order within a phase. Higher priority = earlier execution.0
Built-in priorities:
- Eager resolve: high priority
- Lazy resolve: default priority
- View loading: specific priorities
bind
Sets thethis context for the hook callback.
invokeLimit
Automatically deregisters hook after N invocations.HookResult
The return value from a hook function controls transition behavior.Return Values
false - Cancel Transition
TargetState - Redirect Transition
Promise - Async Hook
void / undefined / true - Continue Transition
Promise Resolution
When a hook returns a Promise:- Resolves to
false→ Transition cancelled - Resolves to
TargetState→ Transition redirected - Resolves to anything else → Transition continues
- Rejects → Transition cancelled with error
Hook Function Signatures
TransitionHookFn
ForonBefore, onStart, onFinish, onSuccess, onError.
TransitionStateHookFn
ForonEnter, onExit, onRetain.
TransitionCreateHookFn
ForonCreate (plugin use only).
Hook Phases
Hooks execute in specific phases during the transition lifecycle.Phase Details
| Phase | Hooks | Can Cancel? | Can Redirect? | Async? |
|---|---|---|---|---|
| CREATE | onCreate | ✅ | ✅ | ❌ |
| BEFORE | onBefore | ✅ | ✅ | ✅ |
| RUN | onStart, onExit, onRetain, onEnter, onFinish | ✅ | ✅ | ✅ |
| SUCCESS | onSuccess | ❌ | ❌ | ❌ |
| ERROR | onError | ❌ | ❌ | ❌ |
RUN Phase Ordering
Within the RUN phase, hooks execute in this order:- onStart (priority 0)
- onExit (priority 100, reverse order - children first)
- onRetain (priority 200)
- onEnter (priority 300, parent to child)
- onFinish (priority 400)
Hook Scope
Hooks have different scopes determining what they match against.TRANSITION Scope
Matches only the tail of the path (final state). Paths with TRANSITION scope:to- destination statefrom- source state
STATE Scope
Matches each state in the path. Paths with STATE scope:entering- each state being enteredexiting- each state being exitedretained- each state being retained
Advanced Patterns
Conditional Default Substate
Lazy Loading Module
Parameter Validation
Unsaved Changes Guard
Role-Based Access Control
Analytics Tracking
Deregistration
All hook registration methods return a deregistration function.Auto-deregistration
TypeScript Definitions
Complete Type Reference
See Also
- TransitionService - Global hook registration
- Transition - Individual transition API