import { Component } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { NgxPermissionsService } from "ngx-permissions"; @Component({ selector: "app-home", templateUrl: "./home.component.html", styleUrls: ["./home.component.less"], }) export class HomeComponent { constructor(private perm: NgxPermissionsService, private router: Router, private route: ActivatedRoute) {} async ngOnInit() { let children = this.route.parent?.routeConfig?.children; const { from } = this.route.snapshot.queryParams; if (Array.isArray(children)) { if (from) { children = children.find((f) => f.path === from)?.children ?? []; } for (const child of children) { if (child.path === this.route.routeConfig?.path) { continue; } const only = child.data?.["permissions"]?.only; if (Array.isArray(only)) { if (await this.perm.hasPermission(only)) { this.router.navigate(["/detection", from, child.path].filter(Boolean)); break; } } } } } }