diff --git a/src/app/pages/cookies/cookies-page.guard.ts b/src/app/pages/cookies/cookies-page.guard.ts index 9875235153..afe96f2567 100644 --- a/src/app/pages/cookies/cookies-page.guard.ts +++ b/src/app/pages/cookies/cookies-page.guard.ts @@ -1,4 +1,5 @@ -import { Injectable } from '@angular/core'; +import { isPlatformBrowser } from '@angular/common'; +import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; import { CanActivate, NavigationEnd, Router } from '@angular/router'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { filter, first } from 'rxjs/operators'; @@ -9,32 +10,38 @@ import { CookiesModalComponent } from './cookies-modal/cookies-modal.component'; export class CookiesPageGuard implements CanActivate { private currentDialog: NgbModalRef; - constructor(private modalService: NgbModal, private router: Router) {} + constructor( + @Inject(PLATFORM_ID) private platformId: string, + private modalService: NgbModal, + private router: Router + ) {} async canActivate() { - this.currentDialog = this.modalService.open(CookiesModalComponent, { - centered: true, - size: 'lg', - backdrop: 'static', - }); - - const cookiesModalComponent = this.currentDialog.componentInstance as CookiesModalComponent; + if (isPlatformBrowser(this.platformId)) { + this.currentDialog = this.modalService.open(CookiesModalComponent, { + centered: true, + size: 'lg', + backdrop: 'static', + }); - // dialog closed - cookiesModalComponent.closeModal.pipe(first()).subscribe(() => { - this.currentDialog.dismiss(); - }); + const cookiesModalComponent = this.currentDialog.componentInstance as CookiesModalComponent; - // navigated away with link on dialog - this.router.events - .pipe( - filter(event => event instanceof NavigationEnd), - first() - ) - .subscribe(() => { + // dialog closed + cookiesModalComponent.closeModal.pipe(first()).subscribe(() => { this.currentDialog.dismiss(); }); - return false; + // navigated away with link on dialog + this.router.events + .pipe( + filter(event => event instanceof NavigationEnd), + first() + ) + .subscribe(() => { + this.currentDialog.dismiss(); + }); + return false; + } + return true; } }