From 4cbfc60a58f7b7ef0d82c6a2b1a48b67ace3d924 Mon Sep 17 00:00:00 2001 From: ziga Date: Mon, 4 May 2020 23:39:04 +0200 Subject: [PATCH] fix: handle links that embed other elements (#2) This fixes the case, when for example `a` tag, wraps an `img` tag. --- lib/app/router.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/app/router.js b/lib/app/router.js index 235dc50df6e9..635b22e821ff 100644 --- a/lib/app/router.js +++ b/lib/app/router.js @@ -112,8 +112,9 @@ export function createRouter(loadComponent, fallbackComponent) { * @param {*} e */ (e) => { - if (e.target.tagName === 'A') { - const { href, target } = e.target + const link = e.target.closest('a') + if (link) { + const { href, target } = link const targetUrl = new URL(href) const currentUrl = window.location if ( @@ -127,7 +128,7 @@ export function createRouter(loadComponent, fallbackComponent) { e.preventDefault() window.scrollTo({ left: 0, - top: e.target.offsetTop, + top: link.offsetTop, behavior: 'smooth' }) }