I'm creating a guard in Angular that have to return true or false if the route has query params or not.
I've create a service like this that return an Observable true or false:
export class MatchService {
constructor(private route: ActivatedRoute) {}
validateQuerys(): Observable<boolean> {
return this.route.queryParams.pipe(
map(res => {
return res['name'] ? true:false;
})
)
}
}
And now the problem, how to handle it in my canMatch guard?
export class routeMatcher implements CanMatch {
constructor(private matchService: MatchService) {}
canMatch(): boolean {
this.matchService.validateQuerys().subscribe({
next: res => (console.log(res))
// return?
// ¿How I can return true or false?
})
}
}
The problem is that I do not know where to place the return true or false in the canMatch() function.