ui-router-server / url-config / applyUrlConfig
Function: applyUrlConfig()
ts
function applyUrlConfig<T>(router, config?): T;Defined in: url-config.ts:85
Applies RouterUrlConfig to router through urlService.config.strictMode, caseInsensitive and defaultSquashPolicy, 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
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 } from 'lit-ui-router';
import { applyUrlConfig } from 'ui-router-server/url-config';
const router = applyUrlConfig(new UIRouterLit(), urlConfig);
states.forEach((state) => router.stateRegistry.register(state));
// server
import { createServerRouter } from 'ui-router-server';
const server = createServerRouter({
mounts: { '/': { routes, config: urlConfig } },
});