Skip to content

Commit

Permalink
fix: handle links that embed other elements (#2)
Browse files Browse the repository at this point in the history
This fixes the case, when for example `a` tag, wraps an `img` tag.
  • Loading branch information
zigomir authored May 4, 2020
1 parent a3df035 commit 4cbfc60
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -127,7 +128,7 @@ export function createRouter(loadComponent, fallbackComponent) {
e.preventDefault()
window.scrollTo({
left: 0,
top: e.target.offsetTop,
top: link.offsetTop,
behavior: 'smooth'
})
}
Expand Down

0 comments on commit 4cbfc60

Please sign in to comment.