From d63e6d4604dfbe4938c7d66832c9202364c5bb64 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Dec 2021 15:01:12 +0100 Subject: Add ability for plugins to register client routes --- .../app/+plugin-pages/plugin-pages.component.ts | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 client/src/app/+plugin-pages/plugin-pages.component.ts (limited to 'client/src/app/+plugin-pages/plugin-pages.component.ts') diff --git a/client/src/app/+plugin-pages/plugin-pages.component.ts b/client/src/app/+plugin-pages/plugin-pages.component.ts new file mode 100644 index 000000000..5f294ee13 --- /dev/null +++ b/client/src/app/+plugin-pages/plugin-pages.component.ts @@ -0,0 +1,31 @@ +import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' +import { PluginService } from '@app/core' + +@Component({ + templateUrl: './plugin-pages.component.html' +}) +export class PluginPagesComponent implements AfterViewInit { + @ViewChild('root') root: ElementRef + + constructor ( + private route: ActivatedRoute, + private router: Router, + private pluginService: PluginService + ) { + + } + + ngAfterViewInit () { + const path = '/' + this.route.snapshot.url.map(u => u.path).join('/') + + const registered = this.pluginService.getRegisteredClientRoute(path) + if (!registered) { + console.log('Could not find registered route %s.', path, this.pluginService.getAllRegisteredClientRoutes()) + + return this.router.navigate([ '/404' ], { skipLocationChange: true }) + } + + registered.onMount({ rootEl: this.root.nativeElement }) + } +} -- cgit v1.2.3