21 lines
548 B
JavaScript
21 lines
548 B
JavaScript
var document = require('global/document')
|
|||
|
|
var window = require('global/window')
|
||
|
|
var assert = require('assert')
|
||
|
|
|
||
|
|
module.exports = history
|
||
|
|
|
||
|
|
// listen to html5 pushstate events
|
||
|
|
// and update router accordingly
|
||
|
|
// fn(str) -> null
|
||
|
|
function history (cb) {
|
||
|
|
assert.equal(typeof cb, 'function', 'sheet-router/history: cb must be a function')
|
||
|
|
window.onpopstate = function () {
|
||
|
|
cb({
|
||
|
|
pathname: document.location.pathname,
|
||
|
|
search: document.location.search,
|
||
|
|
href: document.location.href,
|
||
|
|
hash: document.location.hash
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|