State Tree
UI-Router organizes states into a hierarchical tree structure. This tree forms the foundation of state inheritance, nested views, and URL composition.Tree Structure
States form a tree where each state (except the root) has exactly one parent:Root State
UI-Router automatically creates an implicit root state:StateRegistry
The root state:
- Has an empty name (
'') - Is abstract (cannot be navigated to)
- Serves as the ancestor of all states
- Defines the hash parameter (
#)
Parent-Child Relationships
Implicit Parent (Dot Notation)
Use dots (.) in the state name to define hierarchy:
The child state’s URL is appended to the parent’s URL:
app.dashboard→/app/dashboardapp.settings.profile→/app/settings/profile
Explicit Parent
Setparent explicitly for cleaner names:
State Hierarchy Properties
TheStateObject class represents states with hierarchy metadata:
State Path
Thepath array contains all ancestors:
State Includes
Theincludes object maps ancestor names:
StateService.includes():
Inheritance
Child states inherit properties from parent states.URL Inheritance
URLs are composed hierarchically:Parameter Inheritance
Child states inherit parent parameters:Data Inheritance
Thedata property uses prototypal inheritance:
Resolve Inheritance
Child states can inject parent resolves:Tree Traversal
Get Root State
StateObject.root():
Get Parameters with Inheritance
FromStateObject.parameters():
Tree Changes During Transitions
During a transition, theTreeChanges object tracks which parts of the tree are affected:
Example Tree Changes
Given a transition fromapp.users.list to app.settings.profile:
Abstract States as Tree Branches
Abstract states are commonly used as branch points in the tree:Visualizing the Tree
You can visualize the state tree:Best Practices
Use abstract states for layouts
Use abstract states for layouts
Create abstract states to provide layout components for groups of related states.
Keep state names consistent
Keep state names consistent
Use a consistent naming convention:
users(list)users.detail(detail view)users.detail.edit(edit form)
Group related states
Group related states
Use data inheritance for shared properties
Use data inheritance for shared properties
Next Steps
States
Learn about state declarations
Transitions
Understand how transitions navigate the tree
Views
Create nested view hierarchies
URLs & Parameters
Configure hierarchical URLs