Namespace: Navigation:onHistoryChange

Navigation:onHistoryChange

Methods

onHistoryChange(callback, clearOldopt, nullable, usePreviousStateopt, nullable)

Registers an onpopstate event if history API is available (does nothing and warns if not available). Takes a callback, which is provided with states as plain objects like: {state, title, host, path}. Hint: do not rely on title, since that property may only be supported by browsers like Safari, serialize everything important into state and use title as orientation only.

In case of a regular binding all callbacks get the current state, so the state that is being changed to, but if you set "usePreviousState" to true and prior navigation was done with "changeCurrentUrl", all callbacks get two states: "from" and "to". With this you can define rules an behaviour depending on the state you are coming from. Keep in mind: this only works if you use "changeCurrentUrl" for navigation in tandem with this method.

Parameters:
Name Type Attributes Default Description
callback function

function to execute on popstate

clearOld Boolean <optional>
<nullable>
false

defines if old handlers should be removed before setting new one

usePreviousState Boolean <optional>
<nullable>
false

defines if callbacks should be provided with previous state as well (in that case, changeCurrentUrl must have been used for prior navigation)

Source:
See:
Throws:

error if callback is no function

Example
onHistoryChange(function(){ alert('Hey, don\'t do this!'); }, true);