ui-router-signals / RouterSignals
Class: RouterSignals
Defined in: ui-router-signals/src/router-signals.ts:42
A signal mirror of a router's current state.
A single transitionService.onSuccess hook (registered by attach) writes one RouteSnapshot per successful transition into a Signal.State. The public fields are read-only Signal.Computeds over it, so any signal consumer — a watchSelection callback, a framework binding such as lit-ui-router-signals, or a @lit-labs/signals SignalWatcher render — tracks exactly the fields it reads. onSuccess is the only hook a later transition cannot supersede, so every value is a settled route. An onStart hook feeds the two fields about the newest transition, pending and error.
Use the for factory to get the signals for a router: it memoizes one instance (and its transition hooks) per router.
Constructors
Constructor
new RouterSignals(): RouterSignals;Returns
RouterSignals
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
current | readonly | Computed< | StateDeclaration | undefined> | The current state declaration (globals.current). | ui-router-signals/src/router-signals.ts:59 |
error | readonly | Computed<Rejection | undefined> | The newest transition's failure, as core's Rejection: set only for a RejectType.ERROR rejection, such as a throwing resolve, and cleared when the next transition starts. Superseded, redirected, aborted and ignored transitions leave it undefined, as does a success. A failure changes pending and error together. Not part of route. | ui-router-signals/src/router-signals.ts:88 |
params | readonly | Computed<RawParams> | The current parameter values (globals.params), replaced per transition. | ui-router-signals/src/router-signals.ts:63 |
pending | readonly | Computed< | Transition | undefined> | The newest transition still in flight; undefined when none is. A superseded transition never clears its successor, and an error or abort clears it like a success does. Not part of route: every snapshot is a settled route. | ui-router-signals/src/router-signals.ts:77 |
route | readonly | Computed<RouteSnapshot> | The whole route as one value, replaced per transition. Typed by RouteTypes when a registry fills it in. | ui-router-signals/src/router-signals.ts:54 |
transition | readonly | Computed< | Transition | undefined> | The most recent successful transition. | ui-router-signals/src/router-signals.ts:68 |
Methods
attach()
attach(router): () => void;Defined in: ui-router-signals/src/router-signals.ts:130
Starts mirroring the given router. Called by for; call directly only when managing the instance yourself.
Idempotent per router: attaching again to the router already being mirrored returns the same deregistration function instead of registering the hooks again. Calling that function detaches, after which the instance can be attached again.
Parameters
| Parameter | Type |
|---|---|
router | UIRouter |
Returns
the hooks' deregistration function.
() => void
Throws
if already attached to a different router — one instance mirrors one router; use for to get that router's own signals.
for()
static for(router): RouterSignals;Defined in: ui-router-signals/src/router-signals.ts:103
The signals for the given router — one instance per router. The first call attaches the transition hooks; the hooks (and the instance) live as long as the router itself.
Parameters
| Parameter | Type |
|---|---|
router | UIRouter |
Returns
RouterSignals
includes()
includes(stateOrName, params?): boolean;Defined in: ui-router-signals/src/router-signals.ts:166
Tracked StateService.includes, evaluated against the current route: is the state (or glob pattern, e.g. 'admin.**') included in the settled active state? Reading it inside a computed or watcher subscribes to every transition.
Parameters
| Parameter | Type |
|---|---|
stateOrName | StateOrName |
params? | RawParams |
Returns
boolean