Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Detect internal link on plugin pages

Chocobozzz797c2f432f96
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 cf62d1bd7f..7a1eb654f5 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 @@
-<div #root></div>
+<div (click)="onRootClick($event)" #root></div>
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 2111ac7b75..36d05766b6 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')