Class: ClientRouter
Defined in: packages/core/src/router/ClientRouter.ts:43
The client-side implementation of the Router interface.
Extends
Constructors
new ClientRouter()
new ClientRouter(
pageManager
,factory
,dispatcher
,window
,settings
):ClientRouter
Defined in: packages/core/src/router/ClientRouter.ts:81
Initializes the client-side router.
Parameters
pageManager
The page manager handling UI rendering, and transitions between pages if at the client side.
factory
Factory for routes.
dispatcher
Dispatcher fires events to app.
window
The current global client-side APIs provider.
settings
$Router settings.
undefined
| number
| { isSPARouted
: (url
, action
?) => boolean
; middlewareTimeout
: number
; }
Returns
Overrides
Properties
_currentlyRoutedPath
protected
_currentlyRoutedPath:string
=''
Defined in: packages/core/src/router/AbstractRouter.ts:93
Inherited from
AbstractRouter
._currentlyRoutedPath
_currentMiddlewareId
protected
_currentMiddlewareId:number
=0
Defined in: packages/core/src/router/AbstractRouter.ts:92
Middleware ID counter which is used to auto-generate unique middleware names when adding them to routeHandlers map.
Inherited from
AbstractRouter
._currentMiddlewareId
_dispatcher
protected
_dispatcher:Dispatcher
Defined in: packages/core/src/router/AbstractRouter.ts:62
Dispatcher fires events to app.
Inherited from
_factory
protected
_factory:RouteFactory
Defined in: packages/core/src/router/AbstractRouter.ts:58
Factory for routes.
Inherited from
_host
protected
_host:string
=''
Defined in: packages/core/src/router/AbstractRouter.ts:71
The application's host.
Inherited from
_isSPARouted
protected
_isSPARouted:undefined
| (url
,action
?) =>boolean
Defined in: packages/core/src/router/AbstractRouter.ts:95
Inherited from
_languagePartPath
protected
_languagePartPath:string
=''
Defined in: packages/core/src/router/AbstractRouter.ts:80
The URL path fragment used as a suffix to the _root
field
that specifies the current language.
Inherited from
AbstractRouter
._languagePartPath
_middlewareTimeout
protected
_middlewareTimeout:number
Defined in: packages/core/src/router/AbstractRouter.ts:94
Inherited from
AbstractRouter
._middlewareTimeout
_mountedPromise
protected
_mountedPromise:null
| {promise
:Promise
<void
>;reject
: () =>void
;resolve
: () =>void
; } =null
Defined in: packages/core/src/router/ClientRouter.ts:55
Mounted promise to prevent routing until app is fully mounted.
_pageManager
protected
_pageManager:PageManager
Defined in: packages/core/src/router/AbstractRouter.ts:54
The page manager handling UI rendering, and transitions between pages if at the client side.
Inherited from
_protocol
protected
_protocol:string
=''
Defined in: packages/core/src/router/AbstractRouter.ts:67
The current protocol used to access the application, terminated by a
colon (for example https:
).
Inherited from
_root
protected
_root:string
=''
Defined in: packages/core/src/router/AbstractRouter.ts:75
The URL path pointing to the application's root.
Inherited from
_routeHandlers
protected
_routeHandlers:Map
<string
,AbstractRoute
<string
|RoutePathExpression
> |RouterMiddleware
>
Defined in: packages/core/src/router/AbstractRouter.ts:84
Storage of all known routes and middlewares. The key are their names.
Inherited from
_routerRoots
protected
_routerRoots:EventTarget
[] =[]
Defined in: packages/core/src/router/ClientRouter.ts:50
_window
protected
_window:Window
Defined in: packages/core/src/router/ClientRouter.ts:44
Accessors
$dependencies
Get Signature
get
static
$dependencies():Dependencies
Defined in: packages/core/src/router/ClientRouter.ts:61
Returns
Methods
_boundHandleClick()
protected
_boundHandleClick(event
):void
Defined in: packages/core/src/router/ClientRouter.ts:45
Parameters
event
Event
Returns
void
_boundHandlePopState()
protected
_boundHandlePopState(event
):void
Defined in: packages/core/src/router/ClientRouter.ts:47
Parameters
event
Event
Returns
void
_extractRoutePath()
protected
_extractRoutePath(path
):string
Defined in: packages/core/src/router/AbstractRouter.ts:533
Strips the URL path part that points to the application's root (base URL) from the provided path.
Parameters
path
string
Relative or absolute URL path.
Returns
string
URL path relative to the application's base URL.
Inherited from
AbstractRouter
._extractRoutePath
_getAnchorElement()
_getAnchorElement(
target
):Node
Defined in: packages/core/src/router/ClientRouter.ts:439
The method determines whether an anchor element or a child of an anchor element has been clicked, and if it was, the method returns anchor element else null.
Parameters
target
Node
Returns
Node
_getCurrentlyRoutedPath()
_getCurrentlyRoutedPath():
string
Defined in: packages/core/src/router/AbstractRouter.ts:671
Returns path that is stored in private property when a route
method is called.
Returns
string
Inherited from
AbstractRouter
._getCurrentlyRoutedPath
_getMiddlewaresForRoute()
_getMiddlewaresForRoute(
routeName
):RouterMiddleware
[]
Defined in: packages/core/src/router/AbstractRouter.ts:649
Returns middlewares preceding given route name.
Parameters
routeName
string
Returns
Inherited from
AbstractRouter
._getMiddlewaresForRoute
_handle()
_handle(
route
,params
,options
?,action
?):Promise
<void
|UnknownParameters
>
Defined in: packages/core/src/router/AbstractRouter.ts:556
Handles the provided route and parameters by initializing the route's controller and rendering its state via the route's view.
The result is then sent to the client if used at the server side, or displayed if used as the client side.
Parameters
route
AbstractRoute
<string
| RoutePathExpression
>
The route that should have its associated controller rendered via the associated view.
params
Parameters extracted from the URL path and query.
options?
Partial
<RouteOptions
>
The options overrides route options defined in the
routes.js
configuration file.
action?
An action object describing what triggered this routing.
Returns
Promise
<void
| UnknownParameters
>
A promise that resolves when the page is rendered and the result is sent to the client, or displayed if used at the client side.
Inherited from
_handleClick()
_handleClick(
event
):void
Defined in: packages/core/src/router/ClientRouter.ts:381
Handles a click event. The method performs navigation to the target location of the anchor (if it has one).
The navigation will be handled by the router if the protocol and domain of the anchor's target location (href) is the same as the current, otherwise the method results in a hard redirect.
Parameters
event
MouseEvent
The click event.
Returns
void
_handleFatalError()
_handleFatalError(
error
):void
Defined in: packages/core/src/router/ClientRouter.ts:336
Handle a fatal error application state. IMA handle fatal error when IMA handle error.
Parameters
error
Error
Returns
void
_handlePopState()
_handlePopState(
event
):void
Defined in: packages/core/src/router/ClientRouter.ts:357
Handles a popstate event. The method is performed when the active history entry changes.
The navigation will be handled by the router if the event state is defined
and event is not defaultPrevented
.
Parameters
event
PopStateEvent
The popstate event.
Returns
void
_isHashLink()
_isHashLink(
targetUrl
):boolean
Defined in: packages/core/src/router/ClientRouter.ts:467
Tests whether the provided target URL contains only an update of the hash fragment of the current URL.
Parameters
targetUrl
string
The target URL.
Returns
boolean
true
if the navigation to target URL would
result only in updating the hash fragment of the current URL.
_isSameDomain()
_isSameDomain(
url
?):boolean
Defined in: packages/core/src/router/ClientRouter.ts:490
Tests whether the the protocol and domain of the provided URL are the same as the current.
Parameters
url?
string
= ''
The URL.
Returns
boolean
true
if the protocol and domain of the
provided URL are the same as the current.
_runMiddlewares()
_runMiddlewares(
middlewares
,params
,locals
):Promise
<void
>
Defined in: packages/core/src/router/AbstractRouter.ts:684
Runs provided middlewares in sequence.
Parameters
middlewares
Array of middlewares.
undefined
| RouterMiddleware
[]
params
Router params that can be mutated by middlewares.
locals
The locals param is used to pass local data between middlewares.
Returns
Promise
<void
>
Inherited from
AbstractRouter
._runMiddlewares
add()
add(
name
,pathExpression
,controller
,view
,options
?):ClientRouter
Defined in: packages/core/src/router/AbstractRouter.ts:167
Adds a new route to router.
Parameters
name
string
The unique name of this route, identifying it among the rest of the routes in the application.
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
. The name of the parameter is terminated
by a forward slash (/
) or the end of the path expression
string.
The path expression may also contain optional parameters, which
are specified as :?parameterName
. It is recommended to
specify the optional parameters at the end of the path
expression.
controller
The full name of Object Container alias identifying the controller associated with this route.
view
The full name or Object Container alias identifying the view class associated with this route.
options?
Partial
<RouteOptions
>
Additional route options, specified how the navigation to the
route will be handled.
The onlyUpdate
can be either a flag signalling whether
the current controller and view instances should be kept if they
match the ones used by the previous route; or a callback function
that will receive the previous controller and view identifiers
used in the previously matching route, and returns a
boolean
representing the value of the flag. This flag is
disabled by default.
The autoScroll
flag signals whether the page should be
scrolled to the top when the navigation takes place. This flag is
enabled by default.
Returns
This router.
Throws
Thrown if a route with the same name already exists.
Inherited from
getBaseUrl()
getBaseUrl():
string
Defined in: packages/core/src/router/AbstractRouter.ts:243
Returns the application's absolute base URL, pointing to the public root of the application.
Returns
string
The application's base URL.
Inherited from
getCurrentRouteInfo()
getCurrentRouteInfo():
object
Defined in: packages/core/src/router/AbstractRouter.ts:271
Returns the information about the currently active route.
Returns
object
params
params:
RouteParams
<{}>
path
path:
string
route
route:
AbstractRoute
<string
|RoutePathExpression
>
Throws
Thrown if a route is not define for current path.
Inherited from
AbstractRouter
.getCurrentRouteInfo
getDomain()
getDomain():
string
Defined in: packages/core/src/router/AbstractRouter.ts:250
Returns the application's domain in the following form
${protocol}//${host}
.
Returns
string
The current application's domain.