Skip to content

Function: normalizeBasePath()

API / @xmachines/play-router / normalizeBasePath

function normalizeBasePath(basePath?): string;

Defined in: play-router/src/base-path.ts:130

Normalizes a base path, and it substitutes no :param segment of that path.

Use this function when you want the form of the pattern, for example to declare the routes of a machine in a route config of a host that substitutes each param itself. resolveBasePath gives the form that a bridge needs.

Parameters

ParameterTypeDescription
basePath?stringThe prefix, as a pattern or as a concrete path. An absent value, "", and "/" all give "".

Returns

string

The normalized prefix. It starts with /, and it carries no trailing /.

Throws

For a wildcard segment, for an optional :param? segment, for a $param segment, for a query string or a hash fragment, for a URL scheme, for a dot segment (., .., and their percent-encoded forms), and for any segment that a browser rewrites — one that holds whitespace, a backslash, or a character that a URL percent-encodes.

Example

normalizeBasePath("/:machineId/play/"); // "/:machineId/play"
normalizeBasePath("admin"); // "/admin"
normalizeBasePath("/"); // ""