aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+plugin-pages/plugin-pages.component.ts
blob: 973e4d021104bad1d7bb3c8649359a33f62cdf51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 () {
    this.pluginService.ensurePluginsAreLoaded('common')
      .then(() => this.loadRoute())
  }

  private loadRoute () {
    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 })
  }
}