ui-router-server / url-config / applyUrlConfig
Function: applyUrlConfig()
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 Parameter | Description |
|---|---|
T extends UIRouter | 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 | 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
// 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 } },
});