detach SSRd <head> contents

This commit is contained in:
Rich Harris
2017-12-13 20:24:58 -05:00
parent 22d3cb2b1e
commit bffffe0035
3 changed files with 17 additions and 7 deletions

22
runtime/app.js Normal file
View File

@@ -0,0 +1,22 @@
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;