Skip to content

ui-router-server / url-config / applyUrlConfig

Function: applyUrlConfig() ​

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

Defined in: url-config.ts:145

Applies RouterUrlConfig 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 ParameterDescription
T extends UIRouterthe router type, returned unchanged

Parameters ​

ParameterTypeDescription
routerTa router with no url-bearing states or url rules registered yet
config?RouterUrlConfigthe 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 } },
});