]>
Commit | Line | Data |
---|---|---|
d63e6d46 C |
1 | import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
3 | import { PluginService } from '@app/core' | |
4 | ||
5 | @Component({ | |
6 | templateUrl: './plugin-pages.component.html' | |
7 | }) | |
8 | export class PluginPagesComponent implements AfterViewInit { | |
9 | @ViewChild('root') root: ElementRef | |
10 | ||
11 | constructor ( | |
12 | private route: ActivatedRoute, | |
13 | private router: Router, | |
14 | private pluginService: PluginService | |
15 | ) { | |
16 | ||
17 | } | |
18 | ||
19 | ngAfterViewInit () { | |
9d9a3733 C |
20 | this.pluginService.ensurePluginsAreLoaded('common') |
21 | .then(() => this.loadRoute()) | |
22 | } | |
23 | ||
24 | private loadRoute () { | |
d63e6d46 C |
25 | const path = '/' + this.route.snapshot.url.map(u => u.path).join('/') |
26 | ||
27 | const registered = this.pluginService.getRegisteredClientRoute(path) | |
28 | if (!registered) { | |
29 | console.log('Could not find registered route %s.', path, this.pluginService.getAllRegisteredClientRoutes()) | |
30 | ||
31 | return this.router.navigate([ '/404' ], { skipLocationChange: true }) | |
32 | } | |
33 | ||
34 | registered.onMount({ rootEl: this.root.nativeElement }) | |
35 | } | |
36 | } |