Interface DurandalRootRouter

Hierarchy

Index

Properties

Methods

Properties

public activeInstruction: KnockoutObservable

An observable surfacing the active routing instruction that is currently being processed or has recently finished processing. The instruction object has config, fragment, queryString, params and queryParams properties.

public activeItem: DurandalActivator

The active item/screen based on the current navigation state.

optional public guardRoute?: (instance: Object, instruction: DurandalRouteInstruction) => any

Inspects routes and modules before activation. Can be used to protect access by cancelling navigation or redirecting.

param

The module instance that is about to be activated by the router.

param

The route instruction. The instruction object has config, fragment, queryString, params and queryParams properties.

returns

If a boolean, determines whether or not the route should activate or be cancelled. If a string, causes a redirect to the specified route. Can also be a promise for either of these value types.

public handlers: Array<{ routePattern: RegExp; callback: (fragment: string) => void; }>

The route handlers that are registered. Each handler consists of a routePattern and a callback.

public isNavigating: KnockoutComputed

Indicates that the router (or a child router) is currently in the process of navigating.

public navigationModel: KnockoutObservableArray

The route configurations that have been designated as displayable in a nav ui (nav:true).

public routes: DurandalRouteConfiguration[]

The route configs that are registered.

Methods

public activate(options?: DurandalHistoryOptions): JQueryPromise

Activates the router and the underlying history tracking mechanism.

Parameters

Returns

JQueryPromise

A promise that resolves when the router is ready.

public buildNavigationModel(defaultOrder?: number): T in DurandalRouterBase<T>

Builds an observable array designed to bind a navigation UI to. The model will exist in the navigationModel property.

chainable

Parameters

  • defaultOrder?: number optional

    The default order to use for navigation visible routes that don't specify an order. The defualt is 100.

Returns

T in DurandalRouterBase<T>

public convertRouteToHash(route: string): string

Converts a route to a hash suitable for binding to a link's href.

Parameters

  • route: string

Returns

string

The hash.

public convertRouteToModuleId(route: string): string

Converts a route to a module id. This is only called if no module id is supplied as part of the route mapping.

Parameters

  • route: string

Returns

string

The module id.

public convertRouteToTitle(route: string): string

Converts a route to a displayable title. This is only called if no title is specified as part of the route mapping.

method

convertRouteToTitle

Parameters

  • route: string

Returns

string

The title.

public createChildRouter(): T in DurandalRouterBase<T>

Creates a child router.

Returns

T in DurandalRouterBase<T>

The child router.

public deactivate()

Disable history, perhaps temporarily. Not useful in a real app, but possibly useful for unit testing Routers.

public install()

Installs the router's custom ko binding handler.

public loadUrl(fragment: string): boolean

Attempt to load the specified URL fragment. If a route succeeds with a match, returns true. If no defined routes matches the fragment, returns false.

Parameters

  • fragment: string

    The URL fragment to find a match for.

Returns

boolean

True if a match was found, false otherwise.

public makeRelative(settings: string): T in DurandalRouterBase<T>

Makes all configured routes and/or module ids relative to a certain base url.

chainable

Parameters

  • settings: string

    The value is used as the base for routes and module ids.

Returns

T in DurandalRouterBase<T>

public makeRelative(settings: DurandalRelativeRouteSettings): T in DurandalRouterBase<T>

Makes all configured routes and/or module ids relative to a certain base url.

chainable

Parameters

  • settings: DurandalRelativeRouteSettings

    If an object, you can specify route and moduleId separately. In place of specifying route, you can set fromParent:true to make routes automatically relative to the parent router's active route.

Returns

T in DurandalRouterBase<T>

public makeRoutesCaseSensitive()

Makes the RegExp generated for routes case sensitive, rather than the default of case insensitive.

public map(route: string): T in DurandalRouterBase<T>

Maps route patterns to modules.

chainable

Parameters

  • route: string

    A route.

Returns

T in DurandalRouterBase<T>

public map(route: string, moduleId: string): T in DurandalRouterBase<T>

Maps route patterns to modules.

chainable

Parameters

  • route: string

    A route pattern.

  • moduleId: string

    The module id to map the route to.

Returns

T in DurandalRouterBase<T>

public map(route: RegExp, moduleId: string): T in DurandalRouterBase<T>

Maps route patterns to modules.

chainable

Parameters

  • route: RegExp

    A route pattern.

  • moduleId: string

    The module id to map the route to.

Returns

T in DurandalRouterBase<T>

public map(route: string, config: DurandalRouteConfiguration): T in DurandalRouterBase<T>

Maps route patterns to modules.

chainable

Parameters

Returns

T in DurandalRouterBase<T>

public map(route: RegExp, config: DurandalRouteConfiguration): T in DurandalRouterBase<T>

Maps route patterns to modules.

method

map

chainable

Parameters

Returns

T in DurandalRouterBase<T>

public map(config: DurandalRouteConfiguration): T in DurandalRouterBase<T>

Maps route patterns to modules.

chainable

Parameters

Returns

T in DurandalRouterBase<T>

public map(configs: DurandalRouteConfiguration[]): T in DurandalRouterBase<T>

Maps route patterns to modules.

chainable

Parameters

Returns

T in DurandalRouterBase<T>

public mapUnknownRoutes(): T in DurandalRouterBase<T>

Configures the router to map unknown routes to modules at the same path.

chainable

Returns

T in DurandalRouterBase<T>

public mapUnknownRoutes(notFoundModuleId: string, replaceRoute?: string): T in DurandalRouterBase<T>

Configures the router use the specified module id for all unknown routes.

chainable

Parameters

  • notFoundModuleId: string

    Represents the module id to route all unknown routes to.

  • replaceRoute?: string optional

Returns

T in DurandalRouterBase<T>

public mapUnknownRoutes(callback: (instruction: DurandalRouteInstruction) => void): T in DurandalRouterBase<T>

Configures how the router will handle unknown routes.

chainable

Parameters

  • callback: (instruction: DurandalRouteInstruction) => void

    Called back with the route instruction containing the route info. The function can then modify the instruction by adding a moduleId and the router will take over from there.

Returns

T in DurandalRouterBase<T>

public mapUnknownRoutes(config: DurandalRouteConfiguration): T in DurandalRouterBase<T>

Configures how the router will handle unknown routes.

chainable

Parameters

Returns

T in DurandalRouterBase<T>

public navigate(fragment: string, trigger?: boolean): boolean

Save a fragment into the hash history, or replace the URL state if the 'replace' option is passed. You are responsible for properly URL-encoding the fragment in advance. The options object can contain trigger: false if you wish to not have the route callback be fired, or replace: true, if you wish to modify the current URL without adding an entry to the history.

Parameters

  • fragment: string

    The url fragment to navigate to.

  • trigger?: boolean optional

Returns

boolean

Returns true/false from loading the url.

public navigate(fragment: string, options: DurandalNavigationOptions): boolean

Save a fragment into the hash history, or replace the URL state if the 'replace' option is passed. You are responsible for properly URL-encoding the fragment in advance. The options object can contain trigger: false if you wish to not have the route callback be fired, or replace: true, if you wish to modify the current URL without adding an entry to the history.

Parameters

  • fragment: string

    The url fragment to navigate to.

  • options: DurandalNavigationOptions

    An options object with optional trigger and replace flags. You can also pass a boolean directly to set the trigger option. Trigger is true by default.

Returns

boolean

Returns true/false from loading the url.

public navigateBack()

Navigates back in the browser history.

public off(events: string, callback: Function, context?: any): T in DurandalEventSupport<T>

Removes the callbacks for the specified events.

chainable

Parameters

  • events: string
  • callback: Function
  • context?: any optional

Returns

T in DurandalEventSupport<T>

public on(events: string): DurandalEventSubscription

Creates a subscription or registers a callback for the specified event.

Parameters

  • events: string

    One or more events, separated by white space.

Returns

DurandalEventSubscription

A subscription is returned.

public on(events: string, callback: Function, context?: any): T in DurandalEventSupport<T>

Creates a subscription or registers a callback for the specified event.

Parameters

  • events: string

    One or more events, separated by white space.

  • callback: Function
  • context?: any optional

Returns

T in DurandalEventSupport<T>

The events object is returned for chaining.

public parseQueryString(queryString: string): Object

Parses a query string into an object.

Parameters

  • queryString: string

    The query string to parse.

Returns

Object

An object keyed according to the query string parameters.

public proxy(events: string): Function

Creates a function that will trigger the specified events when called. Simplifies proxying jQuery (or other) events through to the events object.

Parameters

  • events: string

    One or more events, separated by white space to trigger by invoking the returned function.

Returns

Function

Calling the function will invoke the previously specified events on the events object.

public reset(): T in DurandalRouterBase<T>

Resets the router by removing handlers, routes, event handlers and previously configured options.

chainable

Returns

T in DurandalRouterBase<T>

public route(routePattern: RegExp, callback: (fragment: string) => void)

Add a route to be tested when the url fragment changes.

Parameters

  • routePattern: RegExp

    The route pattern to test against.

  • callback: (fragment: string) => void

    The callback to execute when the route pattern is matched.

public trigger(events: string, eventArgs?: Array<any>): T in DurandalEventSupport<T>

Triggers the specified events.

chainable

Parameters

  • events: string
  • eventArgs?: Array<any> optional

Returns

T in DurandalEventSupport<T>

public updateDocumentTitle(instance: Object, instruction: DurandalRouteInstruction)

Updates the document title based on the activated module instance, the routing instruction and the app.title.

Parameters

  • instance: Object

    The activated module.

  • instruction: DurandalRouteInstruction

    The routing instruction associated with the action. It has a config property that references the original route mapping config.