本文介绍了Angular2在canActivate Guard中探索已解析的数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在canActivate防护中访问路由的已解析数据(-Resolver).目前,我可以通过
Is it possible to access resolved data of a route (-Resolver) inside a canActivate guard. Currently I can access the resolved data in the component by
ngOnInit() {
this.route.data
.subscribe((data: { example: Array<Object> }) => {
this.example = data.example;
console.log('example resolver', this.example);
});
}
我如何在canActivate守护程序中进行管理?这不起作用:
How could I manage that in the canActivate guard? This is not working:
constructor(private route: ActivatedRoute) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot,
): boolean {
this.route.data
.subscribe((data: { example: Array<Object> }) => {
this.example = data.example;
console.log('example resolver', this.example);
});
}
推荐答案
否,您不能,因为在解析之前会调用canActivate方法,因此您无法获取数据
No, you can't because canActivate Method is called before resolve, so you can't get the data
警卫处理:
-
可以停用
canDeactivate
canLoad
canActivateChild
canActivateChild
canActivate
canActivate
解决
这篇关于Angular2在canActivate Guard中探索已解析的数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!