Class: RouteMatcher

RouteMatcher()

Pure environment-agnostic module for compiling route patterns and matching URLs.

Constructor

new RouteMatcher()

Source:

Methods

(static) _findMatch(routes, decodedPath, basePath, parentDef) → {Object|null}

Recursively finds a route match.

Parameters:
Name Type Default Description
routes Object

The routes configuration

decodedPath string

The decoded path to match against

basePath string

The accumulated base path

parentDef Object | null null

The parent route definition, if any

Source:
Returns:

The match result or null if not found

Type
Object | null

(static) compileRoute(routePattern) → {Object}

Compiles a route pattern into a regular expression, tracking parameter names.

Parameters:
Name Type Description
routePattern string

The route pattern (e.g. '/user/:id').

Source:
Returns:
Type
Object

(static) matchRoute(routes, hash, optionsopt, activeRoutersopt, currentRouteropt) → {object}

Matches a hash string against a collection of routes.

Parameters:
Name Type Attributes Default Description
routes Object:.<string:, any:>

Map of route patterns to definitions.

hash string

The URL hash.

options object <optional>

Router options (e.g. prefix).

activeRouters Iterable:.<object:> <optional>

Active router instances to check for fallback wildcard resolution.

currentRouter object <optional>
null

The current router instance.

Source:
Returns:
Type
object

(static) matches(routes, hash, optionsopt) → {boolean}

Checks if the route definitions have a non-fallback match for the given hash.

Parameters:
Name Type Attributes Description
routes Object:.<string:, any:>

Map of route patterns.

hash string

The URL hash.

options object <optional>

Router options (e.g. prefix).

Source:
Returns:

True if a non-fallback route matches.

Type
boolean

(static) normalizeHash(hash, prefixopt) → {string|null}

Normalizes a hash string with an optional namespace prefix.

Parameters:
Name Type Attributes Description
hash string

Raw hash string (e.g. '#/app1/home').

prefix string <optional>

Namespace prefix (e.g. '/app1').

Source:
Returns:

Normalized hash (e.g. '#/home'), or null if prefix does not match.

Type
string | null