Transitions
A transition represents the process of moving from one state to another in UI-Router. TheTransition class encapsulates all contextual information about this movement.
Transition Class
FromTransition:
Creating Transitions
Transitions are typically created through theStateService:
Using go()
StateService.go():
Using transitionTo()
Transition Options
FromTransitionOptions:
Options Examples
Transition Lifecycle
Transitions execute through several distinct phases:Lifecycle Phases
FromTransitionHookPhase:
Phase Details
BEFORE
The transition hasn’t started yet. onBefore hooks run synchronously.
No resolves have been fetched. Good for authentication checks.
START
Transition is starting. onStart hooks run asynchronously.
Eager resolves are fetched during this phase.
RUN
States are being exited, retained, and entered. Hooks run in order:
- onExit hooks (for exiting states)
- onRetain hooks (for retained states)
- onEnter hooks (for entering states)
- onFinish hooks (just before completion)
TreeChanges
TheTreeChanges object describes which states are affected:
Example: TreeChanges
Transition Context
Accessing State Information
FromTransition:
Accessing Parameters
FromTransition.params():
Dependency Injection
FromTransition.injector():
Transaction Model
UI-Router uses a transaction-based approach to transitions:Atomic Transitions
Transitions are atomic - they either fully succeed or fully fail:Transition Superseding
New transitions supersede old ones:Transition Redirects
Transitions can be redirected:Transition.redirect():
Dynamic Transitions
FromTransition.dynamic():
A transition is dynamic when no states enter/exit but dynamic parameters change:
Ignored Transitions
FromTransition.ignored():
A transition is ignored if:
- No states enter/exit
- No parameters change
Error Handling
FromTransition.error():
Default Error Handler
Set a global error handler:Best Practices
Always handle transition promises
Always handle transition promises
Use hooks for cross-cutting concerns
Use hooks for cross-cutting concerns
Return promises from hooks to wait for async operations
Return promises from hooks to wait for async operations
Use dynamic parameters for UI state
Use dynamic parameters for UI state
Next Steps
Hooks
Learn about transition hooks in detail
States
Understand state declarations
URLs & Parameters
Work with URL parameters
Views
Update views during transitions