Route
Introduction
The Route class represents a resolved route object in @esmx/router. Each navigation produces a Route instance containing complete information about the matched path, parameters, query strings, and associated metadata.
Type Definitions
RouteType
- Type Definition:
Indicates how the navigation was triggered:
push: Standard forward navigation (adds history entry)replace: Replaces current history entryrestartApp: App restart navigationgo: Programmatic history traversal viarouter.go()forward: Forward navigation viarouter.forward()back: Backward navigation viarouter.back()unknown: Navigation triggered by browser popstate eventspushWindow: Opens navigation in a new windowreplaceWindow: Replaces current window locationpushLayer: Opens navigation in a layer
RouteLocation
- Type Definition:
Route location object used for programmatic navigation:
path: Route pathurl: Full URL string or URL objectparams: Route parameters for dynamic segmentsquery: Query string parameters (single values)queryArray: Query string parameters (array values for repeated keys)hash: URL hash fragmentstate: Custom state data persisted in historykeepScrollPosition: Whentrue, maintains current scroll position after navigationstatusCode: HTTP status code for server-side responseslayer: Layer configuration optionsconfirm: Custom confirm handler overriding default route transition logic
RouteLocationInput
- Type Definition:
Input type for navigation methods. Can be a simple path string or a RouteLocation object.
Instance Properties
type
- Type:
RouteType - Read-only:
true
The navigation type that created this route.
path
- Type:
string - Read-only:
true
The path relative to the router base. For matched routes, this is the path with the base prefix removed. For unmatched routes, this equals the full pathname.
fullPath
- Type:
string - Read-only:
true
The complete path including query string and hash.
url
- Type:
URL - Read-only:
true
The full URL object for this route.
params
- Type:
Record<string, string> - Read-only:
true
Dynamic route parameters extracted from the path. For parameters with multiple matches, contains the first value.
paramsArray
- Type:
Record<string, string[]> - Read-only:
true
Dynamic route parameters in array form, useful for parameters that can match multiple segments.
query
- Type:
Record<string, string | undefined> - Read-only:
true
Parsed query string parameters. For repeated keys, contains the first value.
queryArray
- Type:
Record<string, string[] | undefined> - Read-only:
true
Query string parameters in array form, useful for repeated query keys.
hash
- Type:
string - Read-only:
true
The URL hash fragment (including the # prefix).
meta
- Type:
RouteMeta - Read-only:
true
Route metadata from the matched route configuration. Returns an empty object if no route is matched.
matched
- Type:
readonly RouteParsedConfig[] - Read-only:
true
Array of matched route configurations from parent to child. Empty array if no route matches.
config
- Type:
RouteParsedConfig | null - Read-only:
true
The last (deepest) matched route configuration. null if no route matches.
state
- Type:
RouteState - Read-only:
true
Custom state data associated with this route, persisted in browser history.
keepScrollPosition
- Type:
boolean - Read-only:
true
Whether the navigation should maintain the current scroll position rather than scrolling to top.
isPush
- Type:
boolean - Read-only:
true
Whether this route was created by a push-type navigation (push, pushWindow, pushLayer).
statusCode
- Type:
number | null - Read-only:
true
HTTP status code for SSR redirects.
req
- Type:
IncomingMessage | null - Read-only:
true
Node.js HTTP request object (available during SSR).
res
- Type:
ServerResponse | null - Read-only:
true
Node.js HTTP response object (available during SSR).
context
- Type:
Record<string | symbol, any> - Read-only:
true
Shared context object from the router options.
Instance Methods
clone()
- Returns:
Route
Creates a copy of the current route instance with the same configuration and state.