1
0
Fork 0
mirror of synced 2024-09-29 08:41:16 +13:00

bugfix: screenRouter hijacks link clicks and routes when applicable

This commit is contained in:
Michael Shanks 2020-06-03 22:52:33 +01:00
parent 32d1ca641b
commit 5fa8e3ca63
2 changed files with 23 additions and 1 deletions

View file

@ -56,8 +56,30 @@ export const screenRouter = ({ screens, onScreenSelected, appRootPath }) => {
}
}
function click(e) {
const x = e.target.closest("a")
const y = x && x.getAttribute("href")
if (
e.ctrlKey ||
e.metaKey ||
e.altKey ||
e.shiftKey ||
e.button ||
e.defaultPrevented
)
return
const target = x.target || "_self"
if (!y || target !== "_self" || x.host !== location.host) return
e.preventDefault()
route(y)
}
addEventListener("popstate", route)
addEventListener("pushstate", route)
addEventListener("click", click)
return route
}

View file

@ -13,7 +13,7 @@
$: target = openInNewTab ? "_blank" : "_self"
</script>
<a href={_bb.relativeUrl(url)} bind:this={anchorElement} {target}>{text}</a>
<a href={url} bind:this={anchorElement} {target}>{text}</a>
<style>
.textDecoration {