Skip to content

Commit

Permalink
fix: handle links that embed other elements (vuejs#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
yexiaoking authored and veaba committed May 4, 2020
1 parent fdfac38 commit 72eb6e9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/app/router.js
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 72eb6e9

Please sign in to comment.