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, teardownCallback) #

Bind a specific callback to a hash-based route.

addRoute( 'alert', function () { alert( 'something' ); } );
addRoute( /hi-(.*)/, function ( name ) { alert( 'Hi ' + name ) } );
addRoute( /modal/, () => { showModal() }, () => { cleanupModal() } );

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.

teardownCallback function

Callback to be run when hash changes from one that matches to one that doesn't.

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 Attributes Description
path string

String with a route (hash without #).

fromHashchange boolean optional

(Internal) The navigate call originated form a hashchange event, so don't emit another one.

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

Navigate to a specific route.

Parameters:

Name Type Description
title string

Title 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.

onRouterHashChange([event]) #

Handle hashchange events emitted by ourselves

Parameters:

Name Type Attributes Description
event HashChangeEvent optional

Hash change event, if triggered by native event

Source:
Handle hashchange events emitted by ourselves

route() #

Events

hashchange() #

popstate() #

route(routeEvent) #

Event fired whenever the hash changes.

Parameters:

Name Type Description
routeEvent jQuery.Event
Source:
Event fired whenever the hash changes.