mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 19:25:10 +00:00
22 lines
432 B
JavaScript
22 lines
432 B
JavaScript
const app = {
|
|
init(callback) {
|
|
window.addEventListener('click', event => {
|
|
let a = event.target;
|
|
while (a && a.nodeName !== 'A') a = a.parentNode;
|
|
if (!a) return;
|
|
|
|
if (callback(new URL(a.href))) {
|
|
event.preventDefault();
|
|
history.pushState({}, '', a.href);
|
|
}
|
|
});
|
|
|
|
window.addEventListener('popstate', event => {
|
|
callback(window.location);
|
|
});
|
|
|
|
callback(window.location);
|
|
}
|
|
};
|
|
|
|
export default app; |