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

# Function: createServerRouter()

```ts
function createServerRouter<M>(config): ServerRouter<M[keyof M][number]>;
```

Defined in: [index.ts:1029](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/ui-router-server/src/index.ts#L1029)

Compiles a mount table into a resolver. Every mount's routes and redirect
table compile (and validate) at construction, whatever its strategy; a
config with 'simulate' mounts also starts loading @uirouter/core here.
The longest matching mount base owns a pathname outright — a verdict
never falls through to a shorter mount.

A bare mount base ('/app', '/app/') resolves the empty subpath, which
404s unless the mount supplies a root pattern — a rule like
`{ pattern: /^/?$/, to: ... }` or a `url: ''` route. Construction passes
each [diagnoseMounts](diagnoseMounts.md) finding's message to `console.warn` in the
development build, which the `development` and `node` export conditions
resolve; under `node`, only while `NODE_ENV` is not `production`. The
default build never warns.

With `base`, the mount keys spell the base and the router takes it off:
`createServerRouter({ base: '/app/', mounts: { '/app/': ... } })` resolves
as `{ '/': ... }` does, and `resolve` takes paths under the base.

The router's `Decls` is the union of every mount's route declarations:
typed when each `routes` array is `as const`, [RouteDeclaration](../../redirects/interfaces/RouteDeclaration.md)
otherwise.

## Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
|  `M` *extends* `Record`<`string`, readonly [`RouteDeclaration`](../../redirects/interfaces/RouteDeclaration.md)\[]> | `Record`<`string`, readonly [`RouteDeclaration`](../../redirects/interfaces/RouteDeclaration.md)\[]> |

## Parameters

| Parameter | Type |
| ------ | ------ |
| `config` | { `base?`: `string`; `mounts`: { \[B in string | number | symbol]: MountConfig\<M\[B]> }; } & [`ExclusiveMarkers`](../type-aliases/ExclusiveMarkers.md)<`M`\[keyof `M`]\[`number`]> |

## Returns

[`ServerRouter`](../interfaces/ServerRouter.md)<`M`\[keyof `M`]\[`number`]>

## Throws

an `Error` when `base` is relative or a full URL, or a mount key lies outside it
