In UI-Router, a state is a named, self-contained application location. States define the structure of your application and can include URLs, views, data resolves, and more.
export class StateRegistry { /** * Adds a state to the registry * @returns the internal StateObject object */ register(stateDefinition: _StateDeclaration): StateObject; /** * Removes a state from the registry */ deregister(stateOrName: StateOrName): StateObject[]; /** * Gets a registered state */ get(stateOrName?: StateOrName, base?: StateOrName): StateDeclaration | StateDeclaration[];}
const state = { name: 'mystate', onEnter: (transition, state) => { console.log('Entering', state.name); // Can return a promise to delay entry }, onRetain: (transition, state) => { console.log('Retaining', state.name); // Called when state is retained during transition }, onExit: (transition, state) => { console.log('Exiting', state.name); // Can return false to cancel transition }};
When registered, states are converted to StateObject instances:
export class StateObject { /** The parent StateObject */ public parent: StateObject; /** The name used to register the state */ public name: string; /** Prototypally inherits from StateDeclaration.abstract */ public abstract: boolean; /** A compiled URLMatcher which detects when the state's URL is matched */ public url: UrlMatcher; /** The parameters for the state */ public params: { [key: string]: Param }; /** The views for the state */ public views: { [key: string]: _ViewDeclaration }; /** A list of Resolvable objects */ public resolvables: Resolvable[]; /** The original StateDeclaration */ public self: StateDeclaration; /** The parent StateObject objects from this state up to the root */ public path: StateObject[]; /** An object containing the parent States' names as keys */ public includes: { [name: string]: boolean };}