Histery
Single page app history handler.
How to use
$H; // All the callbacks are optional and you can postpone callbacks object// creation by passing a function as a second argument.$H; // By default only pathname is matched, but you can match querystring// and hash too.$H; $H; // You can define leave callback for no match too.$H; // Then we need to start. Suppose my location is /.$H;> go2: sameMatch: false href: / $H;> leave2: sameMatch: false href: /> go3: sameMatch: false href: /test?param=pppp#bababebe rem1: test rem2: pppp rem3: bebe $H;> leave3: sameMatch: false href: /test?param=pppp#bababebe rem1: test rem2: pppp rem3: bebe> go1: sameMatch: false href: /some/reg/expr rem1: reg rem2: expr $H;> leave1: sameMatch: false href: /some/reg/expr rem1: reg rem2: expr> No match: sameMatch: false href: /ololo/piupiu> No match go: sameMatch: false href: /ololo/piupiu $H;> No match leave: sameMatch: true href: /ololo/piupiu> No match: sameMatch: true href: /ololo/piupiu2> No match go: sameMatch: true href: /ololo/piupiu2 $H;> No match leave: sameMatch: false href: /ololo/piupiu2> go2: sameMatch: false href: / $H;> leave2: sameMatch: true href: /> go2: sameMatch: true href: /
State
There is $H.state(key, [value])
method to set or get state entries for
current page.
// Note that $H.state() uses browser's history.state internally and will throw// DataCloneError exception if you'll try to store something that can't be// serialized.$H; console;> Object some: "serializable" value: true // Go to another page.$H; console;> undefined $H; console;> 12345 // Go back in history (same to back button in browser).windowhistory; console;> undefined console;> Object some: "serializable" value: true // Go forward again (same to forward button in browser).windowhistory; console;> 12345