Skip to content

lit-ui-router-signals / RouterSignalController

Class: RouterSignalController<T> ​

Defined in: router-signal-controller.ts:63

A SignalController preselected on the router: watches the RouterSignals of the router the host's nearest provider supplies.

Router discovery matches lit-ui-router-effect's RouterRefController: <ui-router>, <ui-view>, a @lit/context ContextProvider of routerContext and provideRouter all answer, and RouterSignals.for attaches lazily on first use:

ts
class App extends LitElement {
  private active = new RouterSignalController(
    this,
    (route) => route.includes('admin.**'),
  );

  render() {
    return html`...${this.active.value ? 'admin' : ''}...`;
  }
}

If no provider answers (and no explicit or scoped router is given), the controller warns once in development and is a no-op until it reconnects under one or is handed a router with RouterSignalController.setRouter; .value stays at options.initialValue.

Type Parameters ​

Type Parameter
T

Implements ​

Constructors ​

Constructor ​

ts
new RouterSignalController<T>(
   host, 
   selector, 
   options?
): RouterSignalController<T>;

Defined in: router-signal-controller.ts:84

Parameters ​

ParameterType
hostReactiveControllerHost & Element
selector(route) => T
options?RouterSignalControllerOptions<T>

Returns ​

RouterSignalController<T>

Properties ​

PropertyTypeDescriptionDefined in
signals?RouterSignalsThe watched router signals; set once a router is known.router-signal-controller.ts:68
valueTThe selected value, for use in render().router-signal-controller.ts:65

Methods ​

hostConnected() ​

ts
hostConnected(): void;

Defined in: router-signal-controller.ts:122

Called when the host is connected to the component tree. For custom element hosts, this corresponds to the connectedCallback() lifecycle, which is only called when the component is connected to the document.

Returns ​

void

Implementation of ​

ts
ReactiveController.hostConnected

hostDisconnected() ​

ts
hostDisconnected(): void;

Defined in: router-signal-controller.ts:142

Called when the host is disconnected from the component tree. For custom element hosts, this corresponds to the disconnectedCallback() lifecycle, which is called the host or an ancestor component is disconnected from the document.

Returns ​

void

Implementation of ​

ts
ReactiveController.hostDisconnected

setRouter() ​

ts
setRouter(router): void;

Defined in: router-signal-controller.ts:112

Follows router from now on, without asking a provider again. A connected host re-reads .value from the new router's RouterSignals and updates; a disconnected one takes the router on its next hostConnected. The router already followed is a no-op.

Parameters ​

ParameterType
routerUIRouter

Returns ​

void