Expand all

mediawiki.router

Provide navigation routing and location information.

A router responds to hashchange and popstate events.

OOjs Router Copyright 2011-2024 OOjs Team and other contributors. Released under the MIT license http://oojs.mit-license.org

Create an instance of a router that responds to hashchange and popstate events.

Methods

addRoute(path, callback) #

Bind a specific callback to a hash-based route.

addRoute( 'alert', function () { alert( 'something' ); } );
addRoute( /hi-(.*)/, function ( name ) { alert( 'Hi ' + name ) } );

Note that after defining all available routes it is up to the caller to check the existing route via the checkRoute method.

Parameters:

Name Type Description
path string | RegExp

Path to match, string or regular expression

callback function

Callback to be run when hash changes to one that matches.

Source:
Bind a specific callback to a hash-based route.

back() → {jQuery.Promise} #

Navigate to the previous route. This is a wrapper for window.history.back.

Source:

Returns:

Promise which resolves when the back navigation is complete

Type
jQuery.Promise
Navigate to the previous route.

checkRoute() #

Check the current route and run appropriate callback if it matches.

Source:
Check the current route and run appropriate callback if it matches.

getPath() → {string} #

Get current path (hash).

Source:

Returns:

Current path.

Type
string
Get current path (hash).

isSupported() → {boolean} #

Whether the current browser supports 'hashchange' events.

Deprecated:
  • No longer needed
Source:

Returns:

Always true

Type
boolean
Whether the current browser supports 'hashchange' events.

Navigate to a specific 'hash fragment' route.

Parameters:

Name Type Description
path string

String with a route (hash without #).

Deprecated:
Source:
Navigate to a specific 'hash fragment' route.

Navigate to a specific route.

Parameters:

Name Type Description
title string

of new page

options Object
Properties:
Name Type Description
path string

e.g. '/path/' or '/path/#foo'

useReplaceState boolean

Set replaceStateState to use pushState when you want to avoid long history queues.

Source:
Navigate to a specific route.

route() #

Events

hashchange() #

popstate() #

route(routeEvent) #

Parameters:

Name Type Description
routeEvent jQuery.Event
Source: