From 797c2f432f96f096fe0e5b72fa9ffde179e404c5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 20 Jun 2024 09:32:07 +0200 Subject: [PATCH] Detect internal link on plugin pages --- .../plugin-pages.component.html | 2 +- .../plugin-pages.component.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/client/src/app/shared/shared-plugin-pages/plugin-pages.component.html b/client/src/app/shared/shared-plugin-pages/plugin-pages.component.html index cf62d1bd7..7a1eb654f 100644 --- a/client/src/app/shared/shared-plugin-pages/plugin-pages.component.html +++ b/client/src/app/shared/shared-plugin-pages/plugin-pages.component.html @@ -1 +1 @@ -
+
diff --git a/client/src/app/shared/shared-plugin-pages/plugin-pages.component.ts b/client/src/app/shared/shared-plugin-pages/plugin-pages.component.ts index 2111ac7b7..36d05766b 100644 --- a/client/src/app/shared/shared-plugin-pages/plugin-pages.component.ts +++ b/client/src/app/shared/shared-plugin-pages/plugin-pages.component.ts @@ -32,6 +32,25 @@ export class PluginPagesComponent implements OnDestroy, AfterViewInit { 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 () { await this.pluginService.ensurePluginsAreLoaded(this.route.snapshot.data.pluginScope || 'common')