API Docs for: Latest version
Show:

ima.router.AbstractRouter Class

The basic implementation of the ima.router.Router interface, providing the common or default functionality for parts of the API.

Methods

_extractRoutePath

(
  • path
)
String protected

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.

_getRouteByPath

(
  • path
)
?ima.router.Route private

Returns the route matching the provided URL path part. The path may contain a query.

Parameters:

  • path String

    The URL path.

Returns:

?ima.router.Route:

The route matching the path, or null if no such route exists.

_handle

(
  • route
  • params
  • options
)
Promise<Object<string, any>> private

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 ima.router.Route

    The route that should have its associated controller rendered via the associated view.

  • params Object<string, (Error | String)>

    Parameters extracted from the URL path and query.

  • options {onlyUpdate: boolean=, autoScroll: boolean=, allowSPA: boolean=,!~YUIDOC_LINE~! any documentView: ima.page.AbstractDocumentView=}

    The options overrides route options defined in routes.js.

Returns:

Promise<Object<string, any>>:

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.

constructor

(
  • pageManager
  • factory
  • dispatcher
  • ROUTER_CONSTANTS
)

Initializes the router.

Parameters:

  • pageManager ima.page.manager.PageManager

    The page manager handling UI rendering, and transitions between pages if at the client side.

  • factory ima.router.RouteFactory

    Factory for routes.

  • dispatcher ima.event.Dispatcher

    Dispatcher fires events to app.

  • ROUTER_CONSTANTS {ROUTE_NAMES: Object<string, string>, EVENTS: Object<string, string>}

    The internal router constants. The ROUTE_NAMES contains internal route names. The EVENTS contains name of events which are fired with ima.Event.Dispatcher.

Example:

 router.link('article', {articleId: 1});
 router.redirect('http://www.example.com/web');
 router.add(
   'home',
   ns.app.page.home.Controller,
   ns.app.page.home.View,
   { onlyUpdate: false, autoScroll: true, allowSPA: true, documentView: null }
 );

getCurrentRouteInfo

()

getProtocol

()

handleError

()

handleNotFound

()

isClientError

()

isRedirection

()

Properties

_dispatcher

ima.event.Dispatcher private

Dispatcher fires events to app.

_host

String private

The application's host.

Default: ''

_languagePartPath

String private

The URL path fragment used as a suffix to the _root field that specifies the current language.

Default: ''

_pageManager

ima.page.manager.PageManager private

The page manager handling UI rendering, and transitions between pages if at the client side.

_protocol

String private

The current protocol used to access the application, terminated by a colon (for example https:).

Default: ''

_root

String private

The URL path pointing to the application's root.

Default: ''

_routes

Map<string, ima.router.Route> private

Storage of all known routes. The key are the route names.

EVENTS

Object<string, string> final

The internal router events.

ROUTE_NAMES

Object<string, string> final

The internal route names.

RouteNames

Unknown

HTTP status code constants, representing the HTTP status codes recognized and processed by this proxy.

RouteNames.ERROR

String final

The internal route name used for the error page (the 5XX HTTP status code error page).

RouteNames.NOT_FOUND

String final

The internal route name used for the "not found" error page (the 4XX HTTP status code error page).