Class: AbstractRoute<T>
@ima/core.AbstractRoute
Utility for representing and manipulating a single route in the router's configuration.
Type parameters
Name | Type |
---|---|
T | extends string | RoutePathExpression |
Hierarchy
AbstractRoute
Constructors
constructor
• new AbstractRoute<T
>(name
, pathExpression
, controller
, view
, options?
)
Initializes the route.
Type parameters
Name | Type |
---|---|
T | extends string | RoutePathExpression |
Parameters
Name | Type | Description |
---|---|---|
name | string | The unique name of this route, identifying it among the rest of the routes in the application. |
pathExpression | T | Path expression used in route matching, to generate valid path with provided params and parsing params from current path. |
controller | AsyncRouteController | The full name of Object Container alias identifying the controller associated with this route. |
view | AsyncRouteView | The full name or Object Container alias identifying the view class associated with this route. |
options? | Partial <RouteFactoryOptions > | The route additional options. |
Defined in
packages/core/src/router/AbstractRoute.ts:91
Properties
_controller
• Protected
_controller: Object
The full name of Object Container alias identifying the controller associated with this route.
Type declaration
Name | Type |
---|---|
cached | null | RouteController | Promise <RouteController > |
controller | AsyncRouteController |
resolved | boolean |
Defined in
packages/core/src/router/AbstractRoute.ts:58
_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:48
_options
• Protected
_options: RouteFactoryOptions
The route additional options.
Defined in
packages/core/src/router/AbstractRoute.ts:76
_pathExpression
• Protected
_pathExpression: T
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:53
_view
• Protected
_view: Object
The full name or Object Container alias identifying the view class associated with this route.
Type declaration
Name | Type |
---|---|
cached | null | RouteView | Promise <RouteView > |
resolved | boolean |
view | AsyncRouteView |
Defined in
packages/core/src/router/AbstractRoute.ts:67
Methods
extractParameters
▸ extractParameters(path
, baseUrl
): 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 | Description |
---|---|---|
path | string | Currently routed path. |
baseUrl | string | Currently routed baseUrl. |
Returns
RouteParams
<{}>
Map of parameter names to parameter values.
Defined in
packages/core/src/router/AbstractRoute.ts:292
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.
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.
Defined in
packages/core/src/router/AbstractRoute.ts:132
getOptions
▸ getOptions(): RouteFactoryOptions
Return route additional options.
Returns
Defined in
packages/core/src/router/AbstractRoute.ts:210
getPathExpression
▸ getPathExpression(): T
Path expression used in route matching, to generate valid path with provided params and parsing params from current path.
Returns
T
The path expression.
Defined in
packages/core/src/router/AbstractRoute.ts:220
getTrimmedPath
▸ getTrimmedPath(path
): string
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: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.
Defined in
packages/core/src/router/AbstractRoute.ts:185
isAsync
▸ isAsync(module
): boolean
Checks if given argument is an async handler.
Parameters
Name | Type |
---|---|
module | unknown |
Returns
boolean
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
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
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
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:271
preload
▸ preload(): Promise
<[RouteController
, RouteView
]>
Preloads dynamically imported view and controller.
Returns
Promise
<[RouteController
, RouteView
]>
Promise.All resolving to [view, controller] tuple.
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
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.