Angular 2 rc 1 canActivate

限于喜欢 提交于 2019-12-13 16:13:13

问题


Is there some similar like @CanActivate in the new rc router or do I have to use routerOnActivate and navigate back if it is not activable?

Regards


回答1:


The answer as of 15 May 2016 is that @CanActivate functionality is currently not implemented in the release candidate and other than using router-deprecated or switching to an alternate router implementation such as ngrx there really isn't anything to do other than wait.

Here's an open issue asking for a solution: https://github.com/angular/angular/issues/8655

Here is a document which took me ages to find which talks about the proposed router refactorings (you can find mention of @CanActivate in the doc).




回答2:


To use @CanActivate you need to import router-deprecated instead of router.


If you want to use new Router,

there is routerCanDeactivate() lifeCycleHook which is possibly the replacement for @CanActivate.

The only difference would be that, now you'll allow/disallow navigation on previous route instead of the next.



来源:https://stackoverflow.com/questions/37225831/angular-2-rc-1-canactivate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!