Detect internal link on plugin pages
This commit is contained in:
parent
1b9b904c18
commit
797c2f432f
|
@ -1 +1 @@
|
||||||
<div #root></div>
|
<div (click)="onRootClick($event)" #root></div>
|
||||||
|
|
|
@ -32,6 +32,25 @@ export class PluginPagesComponent implements OnDestroy, AfterViewInit {
|
||||||
if (this.urlSub) this.urlSub.unsubscribe()
|
if (this.urlSub) this.urlSub.unsubscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onRootClick (event: Event) {
|
||||||
|
const target = event.target as HTMLElement
|
||||||
|
|
||||||
|
if (!target) return
|
||||||
|
if (target.tagName !== 'A') return
|
||||||
|
|
||||||
|
const a = target as HTMLAnchorElement
|
||||||
|
|
||||||
|
// 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.match(/^https?:\/\//)) {
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
|
||||||
|
this.router.navigateByUrl(href)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async loadRoute () {
|
private async loadRoute () {
|
||||||
await this.pluginService.ensurePluginsAreLoaded(this.route.snapshot.data.pluginScope || 'common')
|
await this.pluginService.ensurePluginsAreLoaded(this.route.snapshot.data.pluginScope || 'common')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue