SpecimenView2Guard.guard.ts 581 B

123456789101112131415161718192021222324252627
  1. import { Injectable } from '@angular/core';
  2. import { CanActivate, Router } from '@angular/router';
  3. @Injectable({
  4. providedIn: 'root'
  5. })
  6. export class SpecimenView2Guard implements CanActivate {
  7. constructor(public router: Router) { }
  8. canActivate(): boolean {
  9. let menus = JSON.parse(localStorage.getItem('menu'));
  10. let can = false;
  11. if (menus) {
  12. menus.forEach((e) => {
  13. if (e.link == 'specimenView2') {
  14. can = true;
  15. }
  16. });
  17. }
  18. if (!can) {
  19. this.router.navigate(['login']);
  20. return false
  21. }
  22. return true;
  23. }
  24. }