CanLoad与CanActivate进行延迟加载 [英] CanLoad vs CanActivate for LazyLoading

查看:77
本文介绍了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天全站免登陆