用于延迟加载的 CanLoad 与 CanActivate [英] CanLoad vs CanActivate for LazyLoading

查看:33
本文介绍了用于延迟加载的 CanLoad 与 CanActivate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用延迟加载并为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 防护.

The CanLoad guard blocks loading of feature module assets until authorized to do so. If you want to both preload a module and guard against unauthorized access, use the CanActivate guard instead.

参见 https://angular.io/docs/ts/latest/guide/router.html#!#preload-canload)

这篇关于用于延迟加载的 CanLoad 与 CanActivate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆