Overview
TheStateObject class is the internal representation of a state in UI-Router. Instances are created when a StateDeclaration is registered with the StateRegistry.
A registered StateDeclaration is augmented with a $$state() getter that returns the corresponding StateObject.
Key Concepts
Prototype chain: StateObject prototypally inherits from its StateDeclaration. Each StateObject property is built using builders from the StateBuilder. Creation: StateObjects are created viaStateObject.create() when states are registered.
Properties
name
The name used to register the state.parent
The parent StateObject.abstract
Abstract state indicator.StateDeclaration.abstract.
url
Compiled URLMatcher.params
State parameters.StateDeclaration.params.
resolve
Resolve configuration.StateDeclaration.resolve.
resolvables
Internal representation of resolves.resolve).
resolvePolicy
Resolve policy configuration.StateDeclaration.resolvePolicy.
views
View configurations.@uirouter/core does not register a builder for views. The framework-specific code should register a
views builder.data
Inherited state data.StateDeclaration.data. This is the only field on StateDeclaration that is mutated - the definition object’s data field is replaced with a new object that prototypally inherits from the parent state definition’s data field.
navigable
Nearest parent state with a URL.path
Path to root.includes
Parent state lookup.true as their values. Used for quick parent state lookups.
self
Original StateDeclaration.The StateObject also prototypally inherits from the
self declaration object.Lifecycle Hook Properties
onEnter
On enter hook.StateDeclaration.onEnter.
onExit
On exit hook.StateDeclaration.onExit.
onRetain
On retain hook.StateDeclaration.onRetain.
Redirect and Lazy Load
redirectTo
Redirect configuration.StateDeclaration.redirectTo.
lazyLoad
Lazy load function.StateDeclaration.lazyLoad.
Static Methods
create
Creates a StateObject from a StateDeclaration.stateDecl- The user-supplied StateDeclaration or state class
- If
stateDeclis a class with@State()decorator, instantiates it - Creates prototype chain: StateObject -> StateObject.prototype -> StateDeclaration
- Adds
$$state()getter to the declaration - Initializes internal cache
isStateClass
Predicate for state classes.true if the object is a class with @State() decorator.
isStateDeclaration
Predicate for state declarations.true if the object is a StateDeclaration (has $$state function).
isState
Predicate for state objects.true if the object is an internal StateObject.
Instance Methods
is
Checks if this state matches a reference.ref- Can be a StateObject instance, StateDeclaration object, or fully-qualified name
true if ref matches the current StateObject instance.
Example:
fqn
Returns the fully-qualified name.root
Returns the root of this state’s tree.parameters
Gets the state’s Param objects.opts.inherit- Iftrue, includes ancestor states’ Params (default:true)opts.matchingKeys- If provided, returns only Params whoseidis a key on this object
parameter
Returns a single Param.id- The name of the parameteropts.inherit- Iftrue, searches ancestor states (default:false)
undefined if not found.
Example:
toString
String representation.Internal Properties
__stateObjectCache
Internal cache object.Construction
constructor
Constructs a StateObject.State Building Process
When a state is registered:- StateQueueManager receives the StateDeclaration
- StateObject.create() creates the StateObject
-
StateBuilder runs builder functions to populate properties:
namebuilder - sets the nameparentbuilder - finds and sets the parenturlbuilder - compiles the URL into a UrlMatcherparamsbuilder - builds Param objectsviewsbuilder - processes view configurationresolvebuilder - converts resolve config to Resolvablesdatabuilder - sets up prototypal inheritancepathbuilder - builds the path arrayincludesbuilder - builds the includes lookup object- And others…
- The fully-built StateObject is stored in the registry
Prototype Chain
The StateObject prototype chain:Example Structure
Comparison with StateDeclaration
StateDeclaration (user-facing):- Configuration object provided by developer
- Plain object with state configuration
- Used for state definition
- Extends to framework-specific properties
- Internal representation created by UI-Router
- Built from StateDeclaration by StateBuilder
- Contains compiled/processed properties (UrlMatcher, Param[], etc.)
- Used internally by the router
See Also
- StateDeclaration - State configuration interface
- StateRegistry - State registration and management
- StateService - State navigation API