UI-Router Core Architecture
UI-Router Core provides a state-based routing framework built around several key architectural components that work together to manage application navigation and state.Core Components
TheUIRouter class is the main entry point and container for all routing services:
Key Services
State Registry
Manages state registration and hierarchy
State Service
API for state transitions and queries
Transition Service
Manages state transition lifecycle and hooks
URL Service
Handles URL routing and synchronization
View Service
Pairs ui-view components with view configurations
Architectural Principles
State-Based Routing
UI-Router uses states instead of URLs as the primary routing mechanism. States can:- Have URLs (optional)
- Nest hierarchically
- Define views, resolves, and parameters
- Be abstract (non-navigable placeholders)
State Tree
States are organized in a hierarchical tree structure. Each state:- Has a unique name (e.g.,
"home","users.detail") - Can have a parent state (implicit from name or explicit)
- Inherits properties from parent states
Transitions
A transition represents movement from one state to another. During a transition:- States are exited (leaving current states)
- States are retained (staying active)
- States are entered (activating new states)
Hierarchical Views
Views can be nested inside other views, creating a hierarchical component structure that mirrors the state tree. See Views for details.Data Flow
Typical Navigation Flow
- Navigation trigger - User action, URL change, or API call
- Target state creation -
StateServicecreates aTargetState - Transition creation -
TransitionServicecreates aTransition - Hook execution - Transition hooks run in phases (onBefore, onStart, onEnter, etc.)
- Resolve fetching - Asynchronous data is fetched
- State activation - States are entered/exited
- View synchronization -
ViewServiceupdates ui-view components - Completion - Transition promise resolves
State Lifecycle
StateObject Structure
States are represented internally asStateObject instances:
Registration
States are registered with theStateRegistry:
URL Management
TheUrlService manages:
- URL synchronization with the browser
- URL rule matching
- Parameter encoding/decoding
- URL generation from states
Plugin System
UI-Router supports plugins to extend functionality:Next Steps
States
Learn about state declarations and configuration
State Tree
Understand hierarchical state organization
Transitions
Explore the transition lifecycle
Hooks
Hook into the transition lifecycle