Skip to content

ui-router-server / ui-router-server / createServerRouter

Function: createServerRouter() ​

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

Defined in: index.ts:1029

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 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 otherwise.

Type Parameters ​

Type ParameterDefault type
M extends Record<string, readonly RouteDeclaration[]>Record<string, readonly RouteDeclaration[]>

Parameters ​

ParameterType
config{ base?: string; mounts: { [B in string | number | symbol]: MountConfig<M[B]> }; } & ExclusiveMarkers<M[keyof M][number]>

Returns ​

ServerRouter<M[keyof M][number]>

Throws ​

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