Class: AbstractRoute
@ima/core.AbstractRoute
Utility for representing and manipulating a single route in the router's configuration.
Hierarchy
AbstractRoute
Constructors
constructor
• new AbstractRoute(name
, pathExpression
, controller
, view
, options
)
Initializes the route.
Parameters
Name | Type | Description |
---|---|---|
name | string | The unique name of this route, identifying it among the rest of the routes in the application. |
pathExpression | string | RoutePathExpression | Path expression used in route matching, to generate valid path with provided params and parsing params from current path. |
controller | string | typeof Controller | () => IController | The full name of Object Container alias identifying the controller associated with this route. |
view | unknown | The full name or Object Container alias identifying the view class associated with this route. |
options | RouteOptions | The route additional options. |
Defined in
packages/core/src/router/AbstractRoute.ts:201
Properties
_cachedController
• Protected
_cachedController: unknown
Defined in
packages/core/src/router/AbstractRoute.ts:53
_cachedView
• Protected
_cachedView: unknown
Defined in
packages/core/src/router/AbstractRoute.ts:54
_controller
• Protected
_controller: string
| typeof Controller
| () => IController
The full name of Object Container alias identifying the controller associated with this route.
Defined in
packages/core/src/router/AbstractRoute.ts:43
_name
• Protected
_name: string
The unique name of this route, identifying it among the rest of the routes in the application.
Defined in
packages/core/src/router/AbstractRoute.ts:33
_options
• Protected
_options: RouteOptions
The route additional options.
Defined in
packages/core/src/router/AbstractRoute.ts:52
_pathExpression
• Protected
_pathExpression: string
| RoutePathExpression
Path expression used in route matching, to generate valid path with provided params and parsing params from current path.
Defined in
packages/core/src/router/AbstractRoute.ts:38
_view
• Protected
_view: unknown
The full name or Object Container alias identifying the view class associated with this route.
Defined in
packages/core/src/router/AbstractRoute.ts:48
Methods
_getAsyncModule
▸ _getAsyncModule(module
): unknown
Helper method to pre-process view and controller which can be async functions in order to support dynamic async routing.
Parameters
Name | Type | Description |
---|---|---|
module | unknown | The module class/alias/constant. |
Returns
unknown
Module, or promise resolving to the actual view or controller constructor function/class.
Defined in
packages/core/src/router/AbstractRoute.ts:362
extractParameters
▸ extractParameters(path?
): RouteParams
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
Name | Type |
---|---|
path? | string |
Returns
RouteParams
Map of parameter names to parameter values.
Defined in
packages/core/src/router/AbstractRoute.ts:347
getController
▸ getController(): unknown
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
unknown
The Controller class/alias/constant.
Defined in
packages/core/src/router/AbstractRoute.ts:251
getName
▸ getName(): string
Returns the unique identifying name of this route.
Returns
string
The name of the route, identifying it.
Defined in
packages/core/src/router/AbstractRoute.ts:239
getOptions
▸ getOptions(): RouteOptions
Return route additional options.
Returns
Defined in
packages/core/src/router/AbstractRoute.ts:278
getPathExpression
▸ getPathExpression(): string
| RoutePathExpression
Path expression used in route matching, to generate valid path with provided params and parsing params from current path.
Returns
string
| RoutePathExpression
The path expression.
Defined in
packages/core/src/router/AbstractRoute.ts:288
getView
▸ getView(): unknown
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
unknown
The View class/alias/constant.
Defined in
packages/core/src/router/AbstractRoute.ts:267
matches
▸ matches(path
): boolean
Tests whether the provided URL path matches this route. The provided path may contain the query.
Parameters
Name | Type | Description |
---|---|---|
path | string | The URL path. |
Returns
boolean
true
if the provided path matches this route.
Defined in
packages/core/src/router/AbstractRoute.ts:328
preload
▸ preload(): Promise
<[unknown
, unknown
]>
Preloads dynamically imported view and controller.
Returns
Promise
<[unknown
, unknown
]>
Promise.All resolving to [view, controller] tuple.
Defined in
packages/core/src/router/AbstractRoute.ts:297
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
Name | Type | Description |
---|---|---|
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.
Defined in
packages/core/src/router/AbstractRoute.ts:314
decodeURIParameter
▸ Static
decodeURIParameter(parameterValue
): string
TODO IMA@18 remove static method
Decoding parameters.
Parameters
Name | Type |
---|---|
parameterValue | string |
Returns
string
decodedValue
Defined in
packages/core/src/router/AbstractRoute.ts:168
getQuery
▸ Static
getQuery(path
): RouteParams
TODO IMA@18 remove static method
Extracts and decodes the query parameters from the provided URL path and query.
Parameters
Name | Type | Description |
---|---|---|
path | string | The URL path, including the optional query string (if any). |
Returns
RouteParams
Parsed query parameters.
Defined in
packages/core/src/router/AbstractRoute.ts:123
getTrimmedPath
▸ Static
getTrimmedPath(path
): string
TODO IMA@18 remove static method
Trims the trailing forward slash from the provided URL path.
Parameters
Name | Type | Description |
---|---|---|
path | string | The path to trim. |
Returns
string
Trimmed path.
Defined in
packages/core/src/router/AbstractRoute.ts:184
pairsToQuery
▸ Static
pairsToQuery(pairs?
): string
TODO IMA@18 remove static method
Converts array of pairs (tuples) into valid URI query component. Filters out invalid inputs (undefined, null, object, array, non-pair).
Example
let pairs = [['a', true], ['hello world', 123]];
pairsToQuery(pairs); // => "?a=true&hello%20world=123"
Parameters
Name | Type | Default value | Description |
---|---|---|---|
pairs? | unknown [][] | [] | Array of arrays where the first element must be string|number and the second element can be any. |
Returns
string
Valid URI query component or empty string if there are no valid pairs provided.
Defined in
packages/core/src/router/AbstractRoute.ts:71
paramsToQuery
▸ Static
paramsToQuery(params?
): string
TODO IMA@18 remove static method
Converts object of key/value pairs to URI query, which can be appended to url.
Parameters
Name | Type |
---|---|
params | RouteParams |
Returns
string