# groutcho › Reference

## elements

| | |
| --- | --- |
| [`RenderPage`](#renderpage) | How an outlet turns a match into content. |
| [`LayoutFn`](#layoutfn) | Layout function shape. |

### `RenderPage`

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

How an outlet turns a match into content.

### `LayoutFn`

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

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

## router

| | |
| --- | --- |
| [`ScrollBehavior`](#scrollbehavior) |  |
| [`RouterOptions`](#routeroptions) |  |
| [`RouterBinding`](#routerbinding) | A router store as signals. |
| [`useRouter`](#userouter) | Use a router in an element. |

### `ScrollBehavior`

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

### `RouterOptions`

```ts
interface RouterOptions
```

| | |
| --- | --- |
| `manageTitle?: boolean` | Mirror the router's title to `document.title`. Defaults to `true`. Turn off when the host page owns the title. |
| `scrollBehavior?: ScrollBehavior` | How to reset scroll after each nav. Defaults to `"top"`. A function gets `(prev, current)` and scrolls however it wants. |

### `RouterBinding`

```ts
interface RouterBinding
```

A router store as signals.

| | |
| --- | --- |
| `readonly store: RouterStore` |  |
| `readonly match: Computed<MatchResult>` | The current match. |
| `readonly title: Computed<string>` | The current title. |
| `readonly go: (input: Input, options?: GoOptions) => MatchResult` |  |
| `readonly get: (name: string) => Route` | Look up a route by name. |

### `useRouter`

```ts
function useRouter(source?: RouterStore | RouterStoreConfig, options: RouterOptions = {}): RouterBinding
```

Use a router in an element. Call it in the element's setup.

Given a config, it creates the router, makes it the page's router, keeps
`document.title` and scroll in step with it, and destroys it when the
element leaves the page. Given a store, it does the same without owning the
store. Given nothing, it returns the page's router.

```ts
define("my-app", () => {
  const { match } = useRouter({ routes });
  return html`<h1>${() => match.value.route?.name}</h1><diso-outlet></diso-outlet>`;
});
```

## From @diso.io/groutcho-core

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