Angular2探索canActivate Guard中的已解决数据?

Max*_*lid 10 router guard resolver angular

是否可以在canActivate防护中访问路径(-Resolver)的已解析数据.目前我可以通过访问组件中已解析的数据

ngOnInit() {
    this.route.data
        .subscribe((data: { example: Array<Object> }) => {
            this.example = data.example;
            console.log('example resolver', this.example);
        });
}
Run Code Online (Sandbox Code Playgroud)

我怎么能在canActivate后卫中管理它?这不起作用:

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);
        });
}
Run Code Online (Sandbox Code Playgroud)

G.V*_*lli 6

,你不能,因为在解析之前调用了 canActivate 方法,所以你无法获取数据

防护处理

  1. 可以停用

  2. 可以加载

  3. canActivateChild

  4. 可以激活

  5. 解决