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 3471afe587
commit 2bedbd5df6
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 {