canload guard Angular2+中的说明



我试图在canload guard中使用combineLatest,但它给我带来了这个错误:类型"预订"缺少类型"可观测"中的以下属性:_isScalar、source、operator、lift和6个其他属性

我的代码看起来像:

canLoad(route: Route): Observable<boolean> {
return combineLatest(this.router.events, this.resources$, this.role$)
.subscribe(([nav, res, role]) => {
// some logic
return false;
})
}

我想通过路由段塞来监听路由事件并检查权限。有人能帮我吗?

您不必使用subscribe,只需返回combineLatest即可。

除了Observable之外的方法,但您返回的是Subscription

canLoad(route: Route): Observable<boolean> {
return combineLatest(this.router.events, this.resources$, this.role$)
.pipe(
// take the first value emitted and complete
first()
map((value) => {
if(value) {
return true;
}
return false;
})
)
}

最新更新