Home Reference Source Test
public class | source

Router

Extends:

Route → Router

Router Base

Constructor Summary

Public Constructor
public

constructor(param: {path: string, target: object|null, routes: Array, exact: boolean, isRoot: boolean})

Method Summary

Public Methods
public

add(route: Route)

Adds new route

public

Adds route block handler to history.

public

Unloads the router

public
public
public

Return last location of history

public

go(index: number): boolean

Changes route by history index.

public

goBack()

Rewinds history

public

Forwards history

public
public

map(fn: *): Array

Iterates child routes

public

onHistoryChange(location: {pathname: string, search: string, state: object}, action: Object)

public

push(path: Object | string, data: Object): Router

Change history by specified path

public

pushRoute(route: Route)

Helper method that pushes the route's url to history

public

redirectRoute(route: Route, action: string)

Redirects route and removes last route record from history

public

renderMatches(matches: Array<{isexact: boolean, params: object, path: string, url: string}>, state: *, action: *)

public

renderRoute(route: Route, match: RouteMatch, state: RouteState): *

Render route

public

replace(path: string, data: data)

Replaces specified path's state

Protected Methods
protected

onRouteExit(action: string)

Triggered when the current route's parent is another router.

protected

onRouteMatch(route: Route, match: {isExact: boolean, params: object, path: string, url: string}, state: Object, action: string): *

Route is matched event handler

protected

Router is activated event handler

protected
protected

Sets the router statically as active router

Inherited Summary

From class Route
public static

of(param: RouteParams): Route

Static helper method to create a new instance of Route

public get

Helper method to return excat path of the component

public

build(match: RouteMatch, state: RouteState, router: Router, view: Page): *

Builds a route's view

public

Clones new instance of the route

public

Clones route's path and returns

public

Returns redirection path

public

Returns route path as string

public

Route has a path

public

matchPath(url: string): Match

Queries if specified url match to the route path

public

Triggered before when an exact match happends.

public
public

String presentation of the component

Public Constructors

public constructor(param: {path: string, target: object|null, routes: Array, exact: boolean, isRoot: boolean}) source

Override:

Route#constructor

Params:

NameTypeAttributeDescription
param {path: string, target: object|null, routes: Array, exact: boolean, isRoot: boolean}

Public Methods

public add(route: Route) source

Adds new route

Params:

NameTypeAttributeDescription
route Route

public addRouteBlocker(fn: RouterBlockHandler): * source

Adds route block handler to history. When history is changed in anywhere then the handler intercepts before history is changed.

Params:

NameTypeAttributeDescription
fn RouterBlockHandler

Return:

*

public dispose() source

Unloads the router

public getHistory(): Object source

Return:

Object

public getHistoryasArray(): Array<string> source

Return:

Array<string>

public getLocation(): RouteLocation source

Return last location of history

Return:

RouteLocation

public go(index: number): boolean source

Changes route by history index.

Params:

NameTypeAttributeDescription
index number

Return:

boolean

public goBack() source

Rewinds history

public goForward() source

Forwards history

public listen(fn: HistoryListener): * source

Params:

NameTypeAttributeDescription
fn HistoryListener

Return:

*

public map(fn: *): Array source

Iterates child routes

Params:

NameTypeAttributeDescription
fn *

Return:

Array

public onHistoryChange(location: {pathname: string, search: string, state: object}, action: Object) source

Params:

NameTypeAttributeDescription
location {pathname: string, search: string, state: object}
action Object

public push(path: Object | string, data: Object): Router source

Change history by specified path

Params:

NameTypeAttributeDescription
path Object | string

Path or matches of the route

data Object
  • optional
  • default: {}
  • nullable: false

data

Return:

Router

public pushRoute(route: Route) source

Helper method that pushes the route's url to history

Params:

NameTypeAttributeDescription
route Route

public redirectRoute(route: Route, action: string) source

Redirects route and removes last route record from history

Params:

NameTypeAttributeDescription
route Route
action string

public renderMatches(matches: Array<{isexact: boolean, params: object, path: string, url: string}>, state: *, action: *) source

Params:

NameTypeAttributeDescription
matches Array<{isexact: boolean, params: object, path: string, url: string}>
state *
action *

public renderRoute(route: Route, match: RouteMatch, state: RouteState): * source

Render route

Params:

NameTypeAttributeDescription
route Route
match RouteMatch
state RouteState

Return:

*

public replace(path: string, data: data) source

Replaces specified path's state

Params:

NameTypeAttributeDescription
path string
data data

Protected Methods

protected onRouteExit(action: string) source

Triggered when the current route's parent is another router.

Params:

NameTypeAttributeDescription
action string

protected onRouteMatch(route: Route, match: {isExact: boolean, params: object, path: string, url: string}, state: Object, action: string): * source

Route is matched event handler

Params:

NameTypeAttributeDescription
route Route
match {isExact: boolean, params: object, path: string, url: string}
state Object
action string

Return:

*

protected onRouterEnter(action: string) source

Router is activated event handler

Params:

NameTypeAttributeDescription
action string
  • optional
  • default: null
  • nullable: true

action

protected routeRollback() source

protected setasActiveRouter(action: string) source

Sets the router statically as active router

Params:

NameTypeAttributeDescription
action string