DataGenerate.guard.ts 526 B

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