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

# Function: applyUrlConfig()

```ts
function applyUrlConfig<T>(router, config?): T;
```

Defined in: [url-config.ts:145](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/ui-router-server/src/url-config.ts#L145)

Applies [RouterUrlConfig](../interfaces/RouterUrlConfig.md) to `router` through
`urlService.config.strictMode`, `caseInsensitive` and
`defaultSquashPolicy`, plus a `stateRegistry` url decorator for
`trailingSlash`, and returns the same router.

Call it before registering any state or `when()` rule. Core compiles each
url when it registers, reading these options then, so a later change
never reaches an already registered url. This helper throws instead of
silently doing nothing in that case.

Undefined options keep the router's current value. An invalid
`defaultSquashPolicy` throws core's own error.

## Type Parameters

| Type Parameter | Description |
| ------ | ------ |
|  `T` *extends* [`UIRouter`](https://ui-router.github.io/core/docs/latest/classes/_router_.uirouter.html) | the router type, returned unchanged |

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `router` | `T` | a router with no url-bearing states or url rules registered yet |
| `config?` | [`RouterUrlConfig`](../interfaces/RouterUrlConfig.md) | the options to apply; a mount's `config` fits as is |

## Returns

`T`

`router`, for chaining

## Throws

if a state with a url, or a `when()` url rule, is already registered

## Throws

if `trailingSlash` respells a kind of state while the router is strict

## Example

```ts
// url-config.ts, imported by the client and the server alike
import type { RouterUrlConfig } from 'ui-router-server/url-config';
export const urlConfig = { strict: false } satisfies RouterUrlConfig;

// client
import { UIRouterLit, type LitStateDeclaration } from 'lit-ui-router';
import { applyUrlConfig } from 'ui-router-server/url-config';
declare const states: LitStateDeclaration[];
const router = applyUrlConfig(new UIRouterLit(), urlConfig);
states.forEach((state) => router.stateRegistry.register(state));

// server
import { createServerRouter, type RouteDeclaration } from 'ui-router-server';
declare const routes: RouteDeclaration[];
const server = createServerRouter({
  mounts: { '/': { routes, config: urlConfig } },
});
```
