fix: properly handle svg anchor elements

pull/3989/head
Divyansh Singh 1 year ago
parent 8538e22f2c
commit b785bd6ab3

@ -174,36 +174,39 @@ export function createRouter(
window.addEventListener( window.addEventListener(
'click', 'click',
(e) => { (e) => {
// temporary fix for docsearch action buttons if (
const button = (e.target as Element).closest('button') e.defaultPrevented ||
if (button) return !(e.target instanceof Element) ||
e.target.closest('button') || // temporary fix for docsearch action buttons
e.button !== 0 ||
e.ctrlKey ||
e.shiftKey ||
e.altKey ||
e.metaKey
)
return
const link = (e.target as Element | SVGElement).closest< const link = e.target.closest<HTMLAnchorElement | SVGAElement>('a')
HTMLAnchorElement | SVGAElement
>('a')
if ( if (
link && !link ||
!link.closest('.vp-raw') && link.closest('.vp-raw') ||
(link instanceof SVGElement || !link.download) link.hasAttribute('download') ||
) { link.hasAttribute('target')
const { target } = link )
const linkHref = link.getAttribute('href') return
const linkHref =
link.getAttribute('href') ??
(link instanceof SVGAElement ? link.getAttribute('xlink:href') : null)
if (linkHref == null) return if (linkHref == null) return
const { href, origin, pathname, hash, search } = new URL( const { href, origin, pathname, hash, search } = new URL(
linkHref, linkHref,
link.baseURI link.baseURI
) )
const currentUrl = new URL(location.href) // copy to keep old data const currentUrl = new URL(location.href) // copy to keep old data
// only intercept inbound html links // only intercept inbound html links
if ( if (origin === currentUrl.origin && treatAsHtml(pathname)) {
!e.ctrlKey &&
!e.shiftKey &&
!e.altKey &&
!e.metaKey &&
!target &&
origin === currentUrl.origin &&
treatAsHtml(pathname)
) {
e.preventDefault() e.preventDefault()
if ( if (
pathname === currentUrl.pathname && pathname === currentUrl.pathname &&
@ -231,7 +234,6 @@ export function createRouter(
go(href) go(href)
} }
} }
}
}, },
{ capture: true } { capture: true }
) )

Loading…
Cancel
Save