Skip to content

Class: RouteMap

Documentation / @xmachines/play-react-router / RouteMap

Defined in: play-react-router/src/route-map.ts:54

Bidirectional route mapper for React Router.

Extends BaseRouteMap — all matching logic lives there. This class exists to provide a React Router-specific type name and to allow future adapter-specific extensions without breaking the shared base.

Inherited API:

  • getStateIdByPath(path): string | null — path → state ID
  • getPathByStateId(stateId): string | null — state ID → path pattern

Example

const routeMap = new RouteMap([
{ stateId: "home", path: "/" },
{ stateId: "profile", path: "/profile/:userId" },
{ stateId: "settings", path: "/settings/:section?" },
]);
routeMap.getStateIdByPath("/profile/123"); // "profile"
routeMap.getPathByStateId("home"); // "/"

Extends

Constructors

Constructor

new RouteMap(mappings): RouteMap;

Defined in: play-router/dist/base-route-map.d.ts:81

Build a route map from an array of state ID ↔ path mappings.

Static paths (no :param) are indexed in an O(1) Map. Parameterized paths are compiled to RegExp and grouped into first-segment buckets for efficient candidate selection.

Parameters

ParameterTypeDescription
mappingsBaseRouteMapping[]Array of { stateId, path } entries. Order determines priority when multiple patterns could match the same path.

Returns

RouteMap

Inherited from

BaseRouteMap.constructor

Methods

getPathByStateId()

getPathByStateId(stateId): string | null;

Defined in: play-router/dist/base-route-map.d.ts:111

Look up the path pattern registered for a state ID.

Parameters

ParameterTypeDescription
stateIdstringState machine state ID (e.g., "profile", "#settings")

Returns

string | null

The registered path pattern, or null if the state ID is unknown

Example

map.getPathByStateId("profile"); // "/profile/:userId"
map.getPathByStateId("missing"); // null

Inherited from

BaseRouteMap.getPathByStateId


getStateIdByPath()

getStateIdByPath(path): string | null;

Defined in: play-router/dist/base-route-map.d.ts:98

Resolve a URL path to its mapped state ID.

Strips query strings and hash fragments before matching. Tries an O(1) exact lookup first, then falls back to bucket-indexed pattern matching. Results are cached after the first pattern match.

Parameters

ParameterTypeDescription
pathstringURL pathname, optionally including query/hash (e.g., "/profile/123?ref=nav")

Returns

string | null

The mapped state ID, or null if no route matches

Example

map.getStateIdByPath("/profile/123"); // "profile"
map.getStateIdByPath("/unknown"); // null

Inherited from

BaseRouteMap.getStateIdByPath