From 35b9f0b169584b524a68a088c4e265c1a7419a88 Mon Sep 17 00:00:00 2001 From: Daan Kauwenberg <daan.kauwenberg@gmail.com> Date: Thu, 11 Oct 2018 14:00:42 +0200 Subject: [PATCH] Only search dom for closest A once --- src/theme/scripts/router.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/theme/scripts/router.js b/src/theme/scripts/router.js index 7d0cc7a..9e391f7 100644 --- a/src/theme/scripts/router.js +++ b/src/theme/scripts/router.js @@ -34,9 +34,10 @@ class Router { } async _onLinkClick(event) { - // See if what is clicked has an anchor as parent or is a link itself and create an URL of it - const link = event.target.closest('a') ? new URL(event.target.closest('a').href) : null; - if (!link) return; + // See if what is clicked has an anchor as parent or is a link itself. If so create URL otherwise return. + const linkElement = event.target.closest('a'); + if (!linkElement) return; + const link = new URL(linkElement.href); // If it’s an external link, just navigate. if(link.host !== this._hostname) {