fix: handle links that embed other elements (#2)

This fixes the case, when for example `a` tag, wraps an `img` tag.
pull/7/head
ziga 5 years ago committed by GitHub
parent a3df035bab
commit 4cbfc60a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -112,8 +112,9 @@ export function createRouter(loadComponent, fallbackComponent) {
* @param {*} e * @param {*} e
*/ */
(e) => { (e) => {
if (e.target.tagName === 'A') { const link = e.target.closest('a')
const { href, target } = e.target if (link) {
const { href, target } = link
const targetUrl = new URL(href) const targetUrl = new URL(href)
const currentUrl = window.location const currentUrl = window.location
if ( if (
@ -127,7 +128,7 @@ export function createRouter(loadComponent, fallbackComponent) {
e.preventDefault() e.preventDefault()
window.scrollTo({ window.scrollTo({
left: 0, left: 0,
top: e.target.offsetTop, top: link.offsetTop,
behavior: 'smooth' behavior: 'smooth'
}) })
} }

Loading…
Cancel
Save