---
url: >-
  https://lit-ui-router.dev/api/lit-ui-router-ssr/vite/functions/serverRouterPlugin.md
---
[lit-ui-router-ssr](../../index.md) / [vite](../index.md) / serverRouterPlugin

# Function: serverRouterPlugin()

```ts
function serverRouterPlugin(router, options?): ServerRouterPlugin;
```

Defined in: [packages/lit-ui-router-ssr/src/vite.ts:141](https://github.com/simshanith/lit-ui-router/blob/ef3e46636efc18ec90dbba19adacfdffe05f88f4/packages/lit-ui-router-ssr/src/vite.ts#L141)

`ui-router-server/vite`'s `serverRouterPlugin`, set up for a Lit app: with
[prerender](../interfaces/ServerRouterPluginOptions.md#prerender), the worker loads
the [shim](../interfaces/ServerRouterPluginOptions.md#shim), then
`lit-ui-router-ssr/register`, then any `preload` passed here, each once,
before the prerender script, so the script imports everything statically. Its default export
comes from this module's [definePrerender](definePrerender.md).

`vite dev` and `vite preview` behave as under `ui-router-server/vite`.

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `router` | [`ServerRouter`](/api/ui-router-server/index/interfaces/ServerRouter) | the server router the middleware and the build step read |
| `options?` | [`ServerRouterPluginOptions`](../interfaces/ServerRouterPluginOptions.md) | the Connect adapter's options, plus the build step |

## Returns

[`ServerRouterPlugin`](../interfaces/ServerRouterPlugin.md)

a plugin to spread into `plugins: [...]`

## Throws

from the build step when the script has no default export
function, the built `index.html` is missing, or a listed path matches no
route

## Example

```ts
import { createServerRouter } from 'ui-router-server';
import { serverRouterPlugin } from 'lit-ui-router-ssr/vite';

plugins: [
  serverRouterPlugin(createServerRouter({ mounts }), {
    prerender: './src/prerender.ts',
  }),
],
```
