# groutcho › Other frameworks › Lit › Reference

## context

### `routerContext`

```ts
const routerContext
```

Context for sharing a {@link RouterStore} down the DOM tree. Provide it from a
root element and consume it in `<diso-outlet>` / `<diso-link>` or your
own components.

## controller

| | |
| --- | --- |
| [`ScrollBehavior`](#scrollbehavior) |  |
| [`RouterControllerOptions`](#routercontrolleroptions) |  |
| [`RouterController`](#routercontroller) | Lit ReactiveController that binds a host element to a groutcho router store. |

### `ScrollBehavior`

```ts
type ScrollBehavior =
	| "top"
	| "preserve"
	| "restore"
	| ((prev: MatchResult, current: MatchResult) => void);
```

### `RouterControllerOptions`

```ts
interface RouterControllerOptions
```

| | |
| --- | --- |
| `manageTitle?: boolean` | Mirror `store.title` to `document.title`. Defaults to `true`. Turn off for SSR or when the host page owns the title. |
| `scrollBehavior?: ScrollBehavior` | How to reset scroll after each nav. Defaults to `"top"`. A function lets you inspect `(prev, current)` and scroll however you want. |

### `RouterController`

```ts
class RouterController implements ReactiveController
```

Lit ReactiveController that binds a host element to a groutcho router store.
Pass an existing {@link RouterStore} (e.g. shared via context) or a config to
create one. The host re-renders whenever the current match changes.

```ts
class MyApp extends LitElement {
  router = new RouterController(this, { routes, redirects });
  render() {
    const { match } = this.router;
    return html`<h1>${match.route?.name}</h1>`;
  }
}
```

| | |
| --- | --- |
| `readonly store: RouterStore` |  |
| `constructor(host: ReactiveControllerHost, source: RouterStore \| RouterStoreConfig, options: RouterControllerOptions = {})` |  |
| `get match(): MatchResult` | The current match snapshot. |
| `get title(): string` | Current title (mirrors `store.title`). |
| `go = (input: Input): MatchResult` | Navigate. Bound so it can be passed as a handler. |
| `get(name: string): Route` | Look up a route by name (shorthand for `store.get`). |
| `setTitle(title: string): void` | Imperative title setter (mirrors `store.setTitle`). |
| `onGo(listener: GoListener): () => void` | Subscribe to nav events. Returns an unsubscribe. |
| `onTitle(listener: TitleListener): () => void` | Subscribe to title changes. Returns an unsubscribe. |
| `onError(listener: ErrorListener): () => void` | Subscribe to error changes. Returns an unsubscribe. |
| `hostConnected(): void` |  |
| `hostDisconnected(): void` |  |

## elements

| | |
| --- | --- |
| [`RenderPage`](#renderpage) | How an outlet turns a match into renderable content. |
| [`LayoutFn`](#layoutfn) | Layout function shape. |
| [`DisoOutlet`](#disooutlet) |  |
| [`DisoLink`](#disolink) |  |
| [`DisoNavLink`](#disonavlink) |  |

### `RenderPage`

```ts
type RenderPage = (match: MatchResult) => unknown;
```

How an outlet turns a match into renderable content.

### `LayoutFn`

```ts
type LayoutFn = (match: MatchResult, children: unknown) => unknown;
```

Layout function shape. Receives the current match and the inner content
(already-rendered page or nested layout). Layouts compose outermost-first.

### `DisoOutlet`

```ts
class DisoOutlet extends RouterElement
```

| | |
| --- | --- |
| `@property({ attribute: false }) renderPage?: RenderPage` | Optional custom renderer; overrides the default page handling. |
| `override render(): unknown` |  |

### `DisoLink`

```ts
class DisoLink extends RouterElement
```

| | |
| --- | --- |
| `@property() to = ""` | A url or route name to navigate to. |
| `@property({ attribute: false }) params?: Params` | Params used with a route-name `to` (and to build the href). |
| `@property({ attribute: false }) input?: Input` | A full input object; takes precedence over `to`/`params`. |
| `protected get target(): Input` |  |
| `protected href(): string` |  |
| `protected onClick = (event: MouseEvent): void` |  |
| `override render(): TemplateResult` |  |

### `DisoNavLink`

```ts
class DisoNavLink extends DisoLink
```

| | |
| --- | --- |
| `@property({ attribute: "active-class" }) activeClass = "active"` | Class name added to the `<a>` when active. Defaults to `"active"`. |
| `@property({ attribute: "active-exact", type: Boolean }) activeExact = false` | Match strictly against the current pathname / route-name (no prefix). |
| `override render(): TemplateResult` |  |

## From @diso.io/groutcho-core

Exported as they are in `@diso.io/groutcho-core`: `Component`, `createBrowserHistory`, `createMemoryHistory`, `createRouter`, `ErrorListener`, `GoListener`, `History`, `Input`, `InputObject`, `MatchResult`, `Params`, `RedirectResult`, `RedirectTest`, `Route`, `RouteConfig`, `RouteError`, `RouteInput`, `Router`, `RouterConfig`, `RouteRedirect`, `RouterStore`, `RouterStoreConfig`, `StoreListener`, `TitleListener`, `TitleValue`.
