问题描述
如果我使用延迟加载并为CanLoad"定义了一个保护.是否需要CanActivate"?因为模块可能被有效加载,但随后用户做了一些使CanLoad"无效的事情,但由于它被加载,用户可以通过 CanLoad.
If I use lazy loading and have a guard defined for "CanLoad". Is "CanActivate" needed? As in is it possible for a module to be validly loaded but then the user does something which invalidates the "CanLoad" but since it is loaded the user can gets past the CanLoad.
推荐答案
如果您已经实现了 CanLoad,则延迟加载不需要 CanActivate.
CanActivate is not needed for lazy loading if you already implemented CanLoad.
如果您需要检查未经授权的访问,您可能仍想用 CanActivate 替换 CanLoad.
You may still want to replace the CanLoad with CanActivate if you need to check for unauthorized access.
NG2 文档是这样说的
This is what the NG2 doc says
CanLoad 保护阻止加载功能模块资产,直到获得授权.如果您想要预加载模块并防止未经授权的访问,请改用 CanActivate 防护.
参见 https://angular.io/docs/ts/latest/guide/router.html#!#preload-canload)
这篇关于用于延迟加载的 CanLoad 与 CanActivate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!