Having some difficulties with the guard on my route that has multiple conditions and too many lines of code. Is there a way to make it shorter?
export class GuardService implements CanActivate {
constructor(private router: Router, private apiService: InfoService) { }
canActivate(route: ActivatedRouteSnapshot): Observable<boolean | UrlTree> {
const { id, type } = route.params;
if (Object.keys(CustomerType).includes(type)) {
return this.apiService.get(id).pipe(
map((overview) => {
if (type === 'additional' && overview.main === null) {
return this.navigate([etc]);
}
return true;
}),
catchError(() => false)
);
} else {
return false;
}
}
}
Facing challenges with numerous conditions in the guard code and seeking suggestions on how to simplify it. Any help would be greatly appreciated!