我希望我的身份验证卫士基于定期触发布尔值的可观察对象来允许/限制访问。我的想法是:
auth$ = interval(5000).pipe(map((n) => n % 2 === 0));
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean> | Promise<boolean> | boolean {
return this.auth$;
}
It works when the triggers goes from false
to true
, but not the opposite, looks like the guard is not active anymore then.
每次导航开始时都会触发一次防护。
一旦angular从守卫那里获得了第一个发射,它便退订并使用发射值来允许/禁止路由。
这意味着-您不能定期发出保护值以更改原始发出的值。
您尝试实现的目标可以通过以下方式实现: