import { CanActivate , Router } from '@angular/router' ; import { Injectable } from '@angular/core' ; import { Store } from '@ngrx/store' ; import { Observable } from 'rxjs' ; import { map , tap } from 'rxjs/operators' ; import { AppState , hasDevicePermission } from '../store/index' ; @ Injectable ( ) export class UhkDeviceInitializedGuard implements CanActivate { constructor ( private store , private router ) { } canActivate ( ) { return this . store . select ( hasDevicePermission ) . pipe ( tap ( hasPermission => { if ( hasPermission ) { this . router . navigate ( [ '/detection' ] ) ; } } ) , map ( hasPermission => ! hasPermission ) ) ; } }