Angular2条件路由 [英] Angular2 conditional routing
问题描述
这可能是一个基本问题,但是在Angular2中,有什么方法可以进行条件路由吗?或者,有人会在路由器外执行此操作吗?
This might be a basic question, but in Angular2 is there any way to do conditional routing ? Or, would someone do that outside the router ?
我知道ui-router可以做到这一点,但是我在Angular2s路由器中没有看到类似的东西
I know ui-router had some ability to do this, but I haven't seen anything similar in Angular2s router
推荐答案
更新
在新路由器中可以使用防护装置来代替 https://angular.io/guide/router#milestone-5-route-警卫队
In the new router guards can be used instead https://angular.io/guide/router#milestone-5-route-guards
原始(用于已久的路由器)
original (for the long gone router)
实施CanActivate
生命周期挂钩,如下所示生命周期挂钩在Angular2路由器中,如果要阻止导航,则返回false.
另请参见 https://angular.io/docs/ts/Latest/api/router/CanActivate-var.html
Implement the CanActivate
lifecycle hook like shown here Life cycle hooks in Angular2 router and return false if you want to prevent the navigation.
See also https://angular.io/docs/ts/latest/api/router/CanActivate-var.html
这篇关于Angular2条件路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!