1 import { Component, HostListener, OnDestroy, OnInit } from '@angular/core';
2 import { NavigationEnd, Router, RouterEvent } from '@angular/router';
4 import { Subscription } from 'rxjs';
5 import { filter } from 'rxjs/operators';
7 import { DocService } from '~/app/shared/services/doc.service';
11 templateUrl: './error.component.html',
12 styleUrls: ['./error.component.scss']
14 export class ErrorComponent implements OnDestroy, OnInit {
22 routerSubscription: Subscription;
24 constructor(private router: Router, private docService: DocService) {}
28 this.routerSubscription = this.router.events
29 .pipe(filter((event: RouterEvent) => event instanceof NavigationEnd))
35 @HostListener('window:beforeunload', ['$event']) unloadHandler(event: Event) {
36 event.returnValue = false;
41 this.router.onSameUrlNavigation = 'reload';
42 this.message = history.state.message;
43 this.header = history.state.header;
44 this.section = history.state.section;
45 this.section_info = history.state.section_info;
46 this.icon = history.state.icon;
47 this.source = history.state.source;
48 this.docUrl = this.docService.urlGenerator(this.section);
50 this.router.navigate(['/error']);
55 if (this.routerSubscription) {
56 this.routerSubscription.unsubscribe();