Skip to content

Function: splitLocation()

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

function splitLocation(location): SplitLocation;

Defined in: packages/play-url/src/location.ts:55

Splits a location into its pathname, its query and its fragment.

The search for the # starts at the SECOND character, so a leading # belongs to the pathname. A hash router writes a location of the form #/home, and that location names the path #/home and no fragment. The rule decides # alone, and a ? ends the pathname wherever it stands.

Parameters

ParameterTypeDescription
locationstringThe location string, for example /docs?tab=api#intro.

Returns

SplitLocation

The parts. Each absent part is "", and never undefined.

Example

splitLocation("/docs?tab=api#intro");
// → { pathname: "/docs", query: "tab=api", fragment: "#intro", suffix: "?tab=api#intro" }
splitLocation("#/home"); // → { pathname: "#/home", query: "", fragment: "", suffix: "" }