Skip to main content

Class: StaticRoute

@ima/core.StaticRoute

Utility for representing and manipulating a single static route in the router's configuration using string representation of the path expression with special param fields identified by :paramName prefix.

Hierarchy

Constructors

constructor

new StaticRoute(name, pathExpression, controller, view, options?)

Parameters

NameTypeDescription
namestring-
pathExpressionstringA path expression specifying the URL path part matching this route (must not contain a query string), optionally containing named parameter placeholders specified as :parameterName.
controllerAsyncRouteController-
viewAsyncRouteView-
options?Partial<RouteFactoryOptions>-

Inherit Doc

Overrides

AbstractRoute.constructor

Defined in

packages/core/src/router/StaticRoute.ts:97

Properties

_controller

Protected _controller: Object

The full name of Object Container alias identifying the controller associated with this route.

Type declaration

NameType
cachednull | RouteController | Promise<RouteController>
controllerAsyncRouteController
resolvedboolean

Inherited from

AbstractRoute._controller

Defined in

packages/core/src/router/AbstractRoute.ts:58


_hasParameters

Protected _hasParameters: boolean

Defined in

packages/core/src/router/StaticRoute.ts:87


_matcher

Protected _matcher: RegExp

Defined in

packages/core/src/router/StaticRoute.ts:88


_name

Protected _name: string

The unique name of this route, identifying it among the rest of the routes in the application.

Inherited from

AbstractRoute._name

Defined in

packages/core/src/router/AbstractRoute.ts:48


_options

Protected _options: RouteFactoryOptions

The route additional options.

Inherited from

AbstractRoute._options

Defined in

packages/core/src/router/AbstractRoute.ts:76


_parameterNames

Protected _parameterNames: string[]

Defined in

packages/core/src/router/StaticRoute.ts:86


_pathExpression

Protected _pathExpression: string

Path expression used in route matching, to generate valid path with provided params and parsing params from current path.

Inherited from

AbstractRoute._pathExpression

Defined in

packages/core/src/router/AbstractRoute.ts:53


_trimmedPathExpression

Protected _trimmedPathExpression: string

Defined in

packages/core/src/router/StaticRoute.ts:85


_view

Protected _view: Object

The full name or Object Container alias identifying the view class associated with this route.

Type declaration

NameType
cachednull | RouteView | Promise<RouteView>
resolvedboolean
viewAsyncRouteView

Inherited from

AbstractRoute._view

Defined in

packages/core/src/router/AbstractRoute.ts:67

Methods

_checkOptionalParamsOrder

_checkOptionalParamsOrder(allMainParams): boolean

Check if all optional params are below required ones

Parameters

NameType
allMainParamsstring[]

Returns

boolean

Defined in

packages/core/src/router/StaticRoute.ts:275


_checkParametersOrder

_checkParametersOrder(clearedPathExpr): boolean

Check if main parameters have correct order. It means that required param cannot follow optional one.

Parameters

NameTypeDescription
clearedPathExprstringThe cleared URL path (removed first and last slash, ...).

Returns

boolean

Returns TRUE if order is correct.

Defined in

packages/core/src/router/StaticRoute.ts:301


_cleanOptParamName

_cleanOptParamName(paramName): string

Returns optional param name without "?"

Parameters

NameTypeDescription
paramNamestringFull param name with "?"

Returns

string

Strict param name without "?"

Defined in

packages/core/src/router/StaticRoute.ts:524


_cleanUnusedOptionalParams

_cleanUnusedOptionalParams(path): string

Remove unused optional param placeholders in path.

Parameters

NameType
pathstring

Returns

string

Defined in

packages/core/src/router/StaticRoute.ts:219


_compileToRegExp

_compileToRegExp(pathExpression): RegExp

Compiles the path expression to a regular expression that can be used for easier matching of URL paths against this route, and extracting the path parameter values from the URL path.

Parameters

NameTypeDescription
pathExpressionstringThe path expression to compile.

Returns

RegExp

The compiled regular expression.

Defined in

packages/core/src/router/StaticRoute.ts:402


_extractParameters

_extractParameters(parameterValues): StringParameters

Extract parameters from given path.

Parameters

NameType
parameterValuesstring[]

Returns

StringParameters

Defined in

packages/core/src/router/StaticRoute.ts:490


_getClearParamName

_getClearParamName(rawParam): string

Extract clear parameter name, e.q. '?name' or 'name'

Parameters

NameType
rawParamstring

Returns

string

Defined in

packages/core/src/router/StaticRoute.ts:255


_getParameterNames

_getParameterNames(pathExpression): string[]

Extracts the parameter names from the provided path expression.

Parameters

NameTypeDescription
pathExpressionstringThe path expression.

Returns

string[]

The names of the parameters defined in the provided path expression.

Defined in

packages/core/src/router/StaticRoute.ts:545


_getParameters

_getParameters(path): StringParameters

Parses the provided path and extract the in-path parameters. The method decodes the parameters and returns them in a hash object.

Parameters

NameType
pathstring

Returns

StringParameters

Defined in

packages/core/src/router/StaticRoute.ts:472


_getSubparamPattern

_getSubparamPattern(delimiter): string

Get pattern for subparameter.

Parameters

NameType
delimiterstring

Returns

string

Defined in

packages/core/src/router/StaticRoute.ts:266


_isOptionalParamInPath

_isOptionalParamInPath(path, paramName): boolean

Returns true, if paramName is placed in path.

Parameters

NameType
pathstring
paramNamestring

Returns

boolean

Defined in

packages/core/src/router/StaticRoute.ts:237


_isParamOptional

_isParamOptional(paramName): boolean

Checks if parameter is optional or not.

Parameters

NameType
paramNamestring

Returns

boolean

return true if is optional, otherwise false

Defined in

packages/core/src/router/StaticRoute.ts:534


_isRequiredParamInPath

_isRequiredParamInPath(path, paramName): boolean

Returns true, if paramName is placed in path and it's required.

Parameters

NameType
pathstring
paramNamestring

Returns

boolean

Defined in

packages/core/src/router/StaticRoute.ts:246


_replaceOptionalParametersInPath

_replaceOptionalParametersInPath(path, optionalParams): string

Convert main optional parameters to capture sequences

Parameters

NameTypeDescription
pathstringThe URL path.
optionalParamsstring[]List of main optimal parameter expressions

Returns

string

RegExp pattern.

Defined in

packages/core/src/router/StaticRoute.ts:319


_replaceOptionalSubParametersInPath

_replaceOptionalSubParametersInPath(path, optionalSubparamsOthers, optionalSubparamsLast): string

Convert optional subparameters to capture sequences

Parameters

NameTypeDescription
pathstringThe URL path (route definition).
optionalSubparamsOthersstring[]List of all subparam. expressions but last ones
optionalSubparamsLaststring[]List of last subparam. expressions

Returns

string

RegExp pattern.

Defined in

packages/core/src/router/StaticRoute.ts:370


_replaceRequiredSubParametersInPath

_replaceRequiredSubParametersInPath(path, clearedPathExpr): string

Convert required subparameters to capture sequences

Parameters

NameTypeDescription
pathstringThe URL path (route definition).
clearedPathExprstringThe original cleared URL path.

Returns

string

RegExp pattern.

Defined in

packages/core/src/router/StaticRoute.ts:337


_substituteOptionalParamInPath

_substituteOptionalParamInPath(path, paramName, paramValue): string

Replace optional param placeholder in path with parameter value.

Parameters

NameType
pathstring
paramNamestring
paramValuestring

Returns

string

Defined in

packages/core/src/router/StaticRoute.ts:204


_substituteRequiredParamInPath

_substituteRequiredParamInPath(path, paramName, paramValue): string

Replace required parameter placeholder in path with parameter value.

Parameters

NameType
pathstring
paramNamestring
paramValuestring

Returns

string

Defined in

packages/core/src/router/StaticRoute.ts:190


extractParameters

extractParameters(path, baseUrl): Object

Extracts the parameter values from the provided path. The method extracts both the in-path parameters and parses the query, allowing the query parameters to override the in-path parameters.

The method returns an empty hash object if the path does not match this route.

Parameters

NameTypeDescription
pathstringCurrently routed path.
baseUrlstringCurrently routed baseUrl.

Returns

Object

Map of parameter names to parameter values.

Overrides

AbstractRoute.extractParameters

Defined in

packages/core/src/router/StaticRoute.ts:177


getController

getController(): RouteController | Promise<RouteController>

Returns Controller class/alias/constant associated with this route. Internally caches async calls for dynamically imported controllers, meaning that once they're loaded, you get the same promise for subsequent calls.

Returns

RouteController | Promise<RouteController>

The Controller class/alias/constant.

Inherited from

AbstractRoute.getController

Defined in

packages/core/src/router/AbstractRoute.ts:153


getName

getName(): string

Returns the unique identifying name of this route.

Returns

string

The name of the route, identifying it.

Inherited from

AbstractRoute.getName

Defined in

packages/core/src/router/AbstractRoute.ts:132


getOptions

getOptions(): RouteFactoryOptions

Return route additional options.

Returns

RouteFactoryOptions

Inherited from

AbstractRoute.getOptions

Defined in

packages/core/src/router/AbstractRoute.ts:210


getPathExpression

getPathExpression(): string

Path expression used in route matching, to generate valid path with provided params and parsing params from current path.

Returns

string

The path expression.

Inherited from

AbstractRoute.getPathExpression

Defined in

packages/core/src/router/AbstractRoute.ts:220


getTrimmedPath

getTrimmedPath(path): string

Trims the trailing forward slash from the provided URL path.

Parameters

NameTypeDescription
pathstringThe path to trim.

Returns

string

Trimmed path.

Inherited from

AbstractRoute.getTrimmedPath

Defined in

packages/core/src/router/AbstractRoute.ts:230


getView

getView(): RouteView | Promise<RouteView>

Returns View class/alias/constant associated with this route. Internally caches async calls for dynamically imported views, meaning that once they're loaded, you get the same promise for subsequent calls.

Returns

RouteView | Promise<RouteView>

The View class/alias/constant.

Inherited from

AbstractRoute.getView

Defined in

packages/core/src/router/AbstractRoute.ts:185


isAsync

isAsync(module): boolean

Checks if given argument is an async handler.

Parameters

NameType
moduleunknown

Returns

boolean

Inherited from

AbstractRoute.isAsync

Defined in

packages/core/src/router/AbstractRoute.ts:139


isControllerResolved

isControllerResolved(): boolean

Returns true for resolved controller. This is always true for sync route views.

Returns

boolean

Inherited from

AbstractRoute.isControllerResolved

Defined in

packages/core/src/router/AbstractRoute.ts:173


isViewResolved

isViewResolved(): boolean

Returns true for resolved view. This is always true for sync route views.

Returns

boolean

Inherited from

AbstractRoute.isViewResolved

Defined in

packages/core/src/router/AbstractRoute.ts:203


matches

matches(path): boolean

Tests whether the provided URL path matches this route. The provided path may contain the query.

Parameters

NameTypeDescription
pathstringThe URL path.

Returns

boolean

true if the provided path matches this route.

Overrides

AbstractRoute.matches

Defined in

packages/core/src/router/StaticRoute.ts:168


preload

preload(): Promise<[RouteController, RouteView]>

Preloads dynamically imported view and controller.

Returns

Promise<[RouteController, RouteView]>

Promise.All resolving to [view, controller] tuple.

Inherited from

AbstractRoute.preload

Defined in

packages/core/src/router/AbstractRoute.ts:239


toPath

toPath(params?): string

Creates the URL and query parts of a URL by substituting the route's parameter placeholders by the provided parameter value.

The extraneous parameters that do not match any of the route's placeholders will be appended as the query string.

Parameters

NameTypeDescription
paramsRouteParamsThe route parameter values.

Returns

string

Path and, if necessary, query parts of the URL representing this route with its parameters replaced by the provided parameter values.

Overrides

AbstractRoute.toPath

Defined in

packages/core/src/router/StaticRoute.ts:132