Skip to main content

Class: StaticRoute

Defined in: packages/core/src/router/StaticRoute.ts:84

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.

Extends

Constructors

new StaticRoute()

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

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

Parameters

name

string

pathExpression

string

A path expression specifying the URL path part matching this route (must not contain a query string), optionally containing named parameter placeholders specified as :parameterName.

controller

AsyncRouteController

view

AsyncRouteView

options?

Partial<RouteFactoryOptions>

Returns

StaticRoute

Inherit Doc

Overrides

AbstractRoute.constructor

Properties

_controller

protected _controller: object

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

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

cached

cached: null | RouteController | Promise<RouteController>

controller

controller: AsyncRouteController

resolved

resolved: boolean

Inherited from

AbstractRoute._controller


_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

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

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

Inherited from

AbstractRoute._name


_options

protected _options: RouteFactoryOptions

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

The route additional options.

Inherited from

AbstractRoute._options


_parameterNames

protected _parameterNames: string[]

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


_pathExpression

protected _pathExpression: string

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

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

Inherited from

AbstractRoute._pathExpression


_trimmedPathExpression

protected _trimmedPathExpression: string

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


_view

protected _view: object

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

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

cached

cached: null | RouteView | Promise<RouteView>

resolved

resolved: boolean

view

view: AsyncRouteView

Inherited from

AbstractRoute._view

Methods

_checkOptionalParamsOrder()

_checkOptionalParamsOrder(allMainParams): boolean

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

Check if all optional params are below required ones

Parameters

allMainParams

string[]

Returns

boolean


_checkParametersOrder()

_checkParametersOrder(clearedPathExpr): boolean

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

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

Parameters

clearedPathExpr

string

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

Returns

boolean

Returns TRUE if order is correct.


_cleanOptParamName()

_cleanOptParamName(paramName): string

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

Returns optional param name without "?"

Parameters

paramName

string

Full param name with "?"

Returns

string

Strict param name without "?"


_cleanUnusedOptionalParams()

_cleanUnusedOptionalParams(path): string

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

Remove unused optional param placeholders in path.

Parameters

path

string

Returns

string


_compileToRegExp()

_compileToRegExp(pathExpression): RegExp

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

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

pathExpression

string

The path expression to compile.

Returns

RegExp

The compiled regular expression.


_extractParameters()

_extractParameters(parameterValues): StringParameters

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

Extract parameters from given path.

Parameters

parameterValues

string[]

Returns

StringParameters


_getClearParamName()

_getClearParamName(rawParam): string

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

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

Parameters

rawParam

string

Returns

string


_getParameterNames()

_getParameterNames(pathExpression): string[]

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

Extracts the parameter names from the provided path expression.

Parameters

pathExpression

string

The path expression.

Returns

string[]

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


_getParameters()

_getParameters(path): StringParameters

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

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

Parameters

path

string

Returns

StringParameters


_getSubparamPattern()

_getSubparamPattern(delimiter): string

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

Get pattern for subparameter.

Parameters

delimiter

string

Returns

string


_isOptionalParamInPath()

_isOptionalParamInPath(path, paramName): boolean

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

Returns true, if paramName is placed in path.

Parameters

path

string

paramName

string

Returns

boolean


_isParamOptional()

_isParamOptional(paramName): boolean

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

Checks if parameter is optional or not.

Parameters

paramName

string

Returns

boolean

return true if is optional, otherwise false


_isRequiredParamInPath()

_isRequiredParamInPath(path, paramName): boolean

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

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

Parameters

path

string

paramName

string

Returns

boolean


_replaceOptionalParametersInPath()

_replaceOptionalParametersInPath(path, optionalParams): string

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

Convert main optional parameters to capture sequences

Parameters

path

string

The URL path.

optionalParams

string[]

List of main optimal parameter expressions

Returns

string

RegExp pattern.


_replaceOptionalSubParametersInPath()

_replaceOptionalSubParametersInPath(path, optionalSubparamsOthers, optionalSubparamsLast): string

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

Convert optional subparameters to capture sequences

Parameters

path

string

The URL path (route definition).

optionalSubparamsOthers

string[]

List of all subparam. expressions but last ones

optionalSubparamsLast

string[]

List of last subparam. expressions

Returns

string

RegExp pattern.


_replaceRequiredSubParametersInPath()

_replaceRequiredSubParametersInPath(path, clearedPathExpr): string

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

Convert required subparameters to capture sequences

Parameters

path

string

The URL path (route definition).

clearedPathExpr

string

The original cleared URL path.

Returns

string

RegExp pattern.


_substituteOptionalParamInPath()

_substituteOptionalParamInPath(path, paramName, paramValue): string

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

Replace optional param placeholder in path with parameter value.

Parameters

path

string

paramName

string

paramValue

string

Returns

string


_substituteRequiredParamInPath()

_substituteRequiredParamInPath(path, paramName, paramValue): string

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

Replace required parameter placeholder in path with parameter value.

Parameters

path

string

paramName

string

paramValue

string

Returns

string


extractParameters()

extractParameters(path, baseUrl): object

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

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

path

string

Currently routed path.

baseUrl

string

Currently routed baseUrl.

Returns

object

Map of parameter names to parameter values.

Overrides

AbstractRoute.extractParameters


getController()

getController(): RouteController | Promise<RouteController>

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

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


getName()

getName(): string

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

Returns the unique identifying name of this route.

Returns

string

The name of the route, identifying it.

Inherited from

AbstractRoute.getName


getOptions()

getOptions(): RouteFactoryOptions

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

Return route additional options.

Returns

RouteFactoryOptions

Inherited from

AbstractRoute.getOptions


getPathExpression()

getPathExpression(): string

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

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


getTrimmedPath()

getTrimmedPath(path): string

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

Trims the trailing forward slash from the provided URL path.

Parameters

path

string

The path to trim.

Returns

string

Trimmed path.

Inherited from

AbstractRoute.getTrimmedPath


getView()

getView(): RouteView | Promise<RouteView>

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

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


isAsync()

isAsync(module): boolean

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

Checks if given argument is an async handler.

Parameters

module

unknown

Returns

boolean

Inherited from

AbstractRoute.isAsync


isControllerResolved()

isControllerResolved(): boolean

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

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

Returns

boolean

Inherited from

AbstractRoute.isControllerResolved


isViewResolved()

isViewResolved(): boolean

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

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

Returns

boolean

Inherited from

AbstractRoute.isViewResolved


matches()

matches(path): boolean

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

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

Parameters

path

string

The URL path.

Returns

boolean

true if the provided path matches this route.

Overrides

AbstractRoute.matches


preload()

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

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

Preloads dynamically imported view and controller.

Returns

Promise<[RouteController, RouteView]>

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

Inherited from

AbstractRoute.preload


toPath()

toPath(params): string

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

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

params

RouteParams = {}

The 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