From 5fa8e3ca6337246ea23184330e3feffc9f80b8e4 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Wed, 3 Jun 2020 22:52:33 +0100 Subject: [PATCH] bugfix: screenRouter hijacks link clicks and routes when applicable --- packages/client/src/render/screenRouter.js | 22 ++++++++++++++++++++ packages/standard-components/src/Link.svelte | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/client/src/render/screenRouter.js b/packages/client/src/render/screenRouter.js index 262ed65f66..64319102f8 100644 --- a/packages/client/src/render/screenRouter.js +++ b/packages/client/src/render/screenRouter.js @@ -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 } diff --git a/packages/standard-components/src/Link.svelte b/packages/standard-components/src/Link.svelte index d557df6abd..ef0b71d62e 100644 --- a/packages/standard-components/src/Link.svelte +++ b/packages/standard-components/src/Link.svelte @@ -13,7 +13,7 @@ $: target = openInNewTab ? "_blank" : "_self" -{text} +{text}