Class: Router

Router(params) → {Router}

new Router(params) → {Router}

Create a Router. Only one Router instance will be created in an application.

Listens to browser location changes and fires when a known route is matched.

Parameters:
Name Type Description
params Object
Properties
Name Type Description
pushState string

if set to false, router will not listen for popstate event and will not override anchor clicks. Default is true.

Fires:
Returns:

singleton

Type
Router

Methods

add(params)

Parameters:
Name Type Description
params Router~Route

A Route object

Parameters:
Name Type Description
params Object
Properties
Name Type Description
href string

The url to navigate to.

replace boolean

[false] - If true will use history.replaceState instead of history.pushState.

Type Definitions

Route

Type:
  • object
Properties:
Name Type Description
pathname string

The url pathname that will trigger this route (eg. /search/:query).

name string

A name for this route.

listener function

The callback function for when this route is triggered.

Events

router:execute

Fired when a matching route is found.

Type:
  • object
Properties:
Name Type Description
pathname string

The matched pathname.

name string

A matched name.

Array.<function()>

Array of matched listeners.

router:nomatch

Fired when no matching route is found.

Type:
  • object
Properties:
Name Type Description
pathname string

The pathname that did not have a match.