Skip to content

Function: resolveBasePath()

API / @xmachines/play-url / index / resolveBasePath

function resolveBasePath(basePath?, params?): ResolvedBasePath;

Defined in: packages/play-url/src/base-path.ts:184

Resolves a base path and its params to the concrete prefix that a browser URL carries.

A bridge calls this function one time, and again on each setBasePath() call. The result is always concrete. stripBasePath therefore compares a literal prefix, and no URLPattern match runs on the hot path of a navigation.

Parameters

ParameterTypeDescription
basePath?stringThe prefix, as a pattern or as a concrete path.
params?Record<string, string | number>The values of the :param segments of basePath.

Returns

ResolvedBasePath

The concrete prefix, and the values of each param for a play.route event.

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.

Throws

When a :param of the prefix has no value.

Example

resolveBasePath("/:machineId/play", { machineId: "abc123" });
// → { path: "/abc123/play", params: { machineId: "abc123" } }
resolveBasePath("/admin");
// → { path: "/admin", params: {} }