---
url: >-
  https://lit-ui-router.dev/reference/lit-ui-router-signals/classes/RouterSignalController.md
---
[lit-ui-router-signals](../index.md) / RouterSignalController

# Class: RouterSignalController\<T>

Defined in: [router-signal-controller.ts:60](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router-signals/src/router-signal-controller.ts#L60)

A [SignalController](SignalController.md) preselected on the router: watches the
[RouterSignals](/reference/ui-router-signals/classes/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](/reference/ui-router-signals/classes/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](#setrouter); `.value` stays at
`options.initialValue`.

## Type Parameters

| Type Parameter |
| ------ |
|  `T` |

## Implements

* [`ReactiveController`](https://lit.dev/docs/api/controllers/#ReactiveController)

## Constructors

### Constructor

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

Defined in: [router-signal-controller.ts:81](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router-signals/src/router-signal-controller.ts#L81)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `host` | [`ReactiveControllerHost`](https://lit.dev/docs/api/controllers/#ReactiveControllerHost) & `Element` |
| `selector` | (`route`) => `T` |
| `options?` | [`RouterSignalControllerOptions`](../interfaces/RouterSignalControllerOptions.md)<`T`> |

#### Returns

`RouterSignalController`<`T`>

## Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
|  `signals?` | [`RouterSignals`](/reference/ui-router-signals/classes/RouterSignals) | The watched router signals; set once a router is known. | [router-signal-controller.ts:65](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router-signals/src/router-signal-controller.ts#L65) |
|  `value` | `T` | The selected value, for use in `render()`. | [router-signal-controller.ts:62](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router-signals/src/router-signal-controller.ts#L62) |

## Methods

### hostConnected()

```ts
hostConnected(): void;
```

Defined in: [router-signal-controller.ts:119](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router-signals/src/router-signal-controller.ts#L119)

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

`ReactiveController.hostConnected`

***

### hostDisconnected()

```ts
hostDisconnected(): void;
```

Defined in: [router-signal-controller.ts:139](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router-signals/src/router-signal-controller.ts#L139)

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

`ReactiveController.hostDisconnected`

***

### setRouter()

```ts
setRouter(router): void;
```

Defined in: [router-signal-controller.ts:109](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router-signals/src/router-signal-controller.ts#L109)

Follows `router` from now on, without asking a provider again. A
connected host re-reads `.value` from the new router's
[RouterSignals](/reference/ui-router-signals/classes/RouterSignals) and updates; a disconnected one takes the router
on its next `hostConnected`. The router already followed is a no-op.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `router` | [`UIRouter`](https://ui-router.github.io/core/docs/latest/classes/_router_.uirouter.html) |

#### Returns

`void`
