Skip to content

Function: stripBasePath()

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

function stripBasePath(pathname, basePath): string | null;

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

Removes the base path from an inbound location of the router.

The return value separates the two cases that make a shared router work:

  • A string is the MACHINE half of the location, for example "/dashboard" of "/abc123/play/dashboard". The bridge matches it against the route map.
  • null means that the location is FOREIGN: it lies outside the mount, so it belongs to the host. The bridge sends no play.route event, AND it runs no corrective navigation. A correction here would drag the user off a page of the host.

The match is exact, and it respects each segment boundary. "/abc/playground" is therefore foreign to the mount "/abc/play".

Parameters

ParameterTypeDescription
pathnamestringA sanitized pathname of the router, with no query and no duplicate slash.
basePathstringThe concrete prefix of resolveBasePath. "" removes nothing.

Returns

string | null

The machine half of the path, or null when the location is foreign.

Example

stripBasePath("/abc123/play/dashboard", "/abc123/play"); // "/dashboard"
stripBasePath("/abc123/play", "/abc123/play"); // "/"
stripBasePath("/settings", "/abc123/play"); // null — the host owns it