added a package guard
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Mark van der Wal 2021-02-05 12:51:43 +01:00
parent b7b168dffb
commit 39993e75da

View File

@ -0,0 +1,19 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot} from '@angular/router';
import {PackageService} from './package.service';
@Injectable({
providedIn: 'root',
})
export class PackageGuardService implements CanActivate {
constructor(private packageService: PackageService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return route.data && route.data.package && this.hasPackageForRoute(route.data.package);
}
private hasPackageForRoute(packageId: string): boolean {
return this.packageService.hasPackage(packageId);
}
}