Better onRootClick implementation

Thanks John
This commit is contained in:
Chocobozzz 2024-06-21 09:51:07 +02:00
parent ab22399da0
commit d5323a641b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE

View File

@ -34,16 +34,15 @@ export class PluginPagesComponent implements OnDestroy, AfterViewInit {
onRootClick (event: Event) {
const target = event.target as HTMLElement
if (!target) return
if (target.tagName !== 'A') return
const a = target as HTMLAnchorElement
const a = target.closest('a')
if (!a) return
// Get the href attribute set by the dev, not the one calculated by JS to detect if it's a relative/external link
const href = a.getAttribute('href')
if (a.target !== '_blank' && href.startsWith('/')) {
if (!a.target && href.startsWith('/')) {
event.preventDefault()
event.stopPropagation()