diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8c13208..26e05ea 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,12 @@ import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core'; -import {ActivatedRoute, NavigationEnd, RouteConfigLoadEnd, Router} from '@angular/router'; +import { + ActivatedRoute, + NavigationEnd, + NavigationError, + NavigationStart, + RouteConfigLoadEnd, + Router +} from '@angular/router'; import {EnvProperties} from './openaireLibrary/utils/properties/env-properties'; import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service'; @@ -43,35 +50,34 @@ export class AppComponent implements OnInit, OnDestroy { this.propertiesService.loadEnvironment() .then(properties => { this.properties = properties; - this.router.events.subscribe(event => { - if (event instanceof RouteConfigLoadEnd && event.route.path.indexOf('stakeholder') !== -1 || - event instanceof NavigationEnd) { - let r = this.route; - while (r.firstChild) { - r = r.firstChild; - } - r.params.subscribe(params => { - if (params['stakeholder']) { - if (!this.stakeholderService.stakeholder || - this.stakeholderService.stakeholder.alias !== params['stakeholder']) { - this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => { - this.stakeholderService.setStakeholder(stakeholder); - this.layoutService.setOpen(true); - }); - } - } else { - this.stakeholderService.setStakeholder(null); - } - }); + this.subscriptions.push(this.router.events.subscribe(() => { + let r = this.route; + while (r.firstChild) { + r = r.firstChild; } - }); - this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { + this.subscriptions.push(r.params.subscribe(params => { + if (params['stakeholder'] && + (!this.stakeholderService.stakeholder || + this.stakeholderService.stakeholder.alias !== params['stakeholder'])) { + if (!this.stakeholderService.stakeholder || + this.stakeholderService.stakeholder.alias !== params['stakeholder']) { + this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => { + this.stakeholderService.setStakeholder(stakeholder); + this.layoutService.setOpen(true); + }); + } + } else { + this.stakeholderService.setStakeholder(null); + } + })); + })); + this.subscriptions.push(this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => { this.user = user; this.loginCheck = true; }, error => { console.log("App couldn't fetch properties"); console.log(error); - }); + })); }); }