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
*/
(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'
})
}

Loading…
Cancel
Save