---
url: >-
  https://lit-ui-router.dev/api/ui-router-server/prerender/functions/prerender.md
---
[ui-router-server](../../index.md) / [prerender](../index.md) / prerender

# Function: prerender()

```ts
function prerender(options): Promise<PrerenderResult>;
```

Defined in: [prerender.ts:311](https://github.com/simshanith/lit-ui-router/blob/3ab90929a8d23dda96e259d7396a274c5b05398e/packages/ui-router-server/src/prerender.ts#L311)

Emits a static site from a mount table's verdicts: a shell verdict becomes
`<subpath>/index.html` holding whatever `render` returns, a redirect
becomes a rules line and no page, a delegating state is listed in
`delegated` and skipped, and the `otherwise` projection becomes the 404
document. A verdict kind this package doesn't know throws rather than being
counted.

It knows no renderer: `render` turns each shell verdict into the file's
text, so any template engine, or a `settle` and a string, can fill it.
`lit-ui-router-ssr`'s `prerender` wraps this loop with a lit render.

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options` | [`PrerenderOptions`](../interfaces/PrerenderOptions.md) | the mount table, the paths, the render, and the hooks |

## Returns

`Promise`<[`PrerenderResult`](../interfaces/PrerenderResult.md)>

what was emitted, planned or written

## Throws

an `Error` when neither `mounts` nor `resolver` is supplied

## Throws

an `Error` when the 404 document needs a default probe and only a `resolver` is supplied

## Throws

an `Error` when a path resolves to a verdict kind this package doesn't know

## Example

```ts
import { mkdir, writeFile } from 'node:fs/promises';
import { dirname } from 'node:path';
import { prerender } from 'ui-router-server/prerender';
import { settle } from 'ui-router-server/ssr';

const result = await prerender({
  mounts,
  outDir: 'dist',
  write: async (file, body) => {
    await mkdir(dirname(file), { recursive: true });
    await writeFile(file, body);
  },
  paths: ['/', '/sheet/7B', '/legacy'],
  render: async (verdict, { path }) => {
    await settle(router, path);
    return page(router);
  },
});
```
