CanActivate vs. CanActivateChild with component-less routes

后端 未结 6 1154
傲寒
傲寒 2020-12-12 18:17

The angular2 documentation about Route Guards left me unclear about when it is appropriate to use a CanActivate guards vs. a CanActivateChild guard

6条回答
  •  爱一瞬间的悲伤
    2020-12-12 18:32

    TL;DR: CanActivate and CanActivateChild are not for a component-less route.

    I believe the docs simply overlooked the needless of both guards in a component-less route, as the intention was simply to demonstrate the component-less route in a particular mile-stone of the docs and the the use of both guards in another.

    The use of both guards can be very useful in specific scenarios, for example: An admin dashboard allowing login to see several components, like mailing, logging statistics, resource usage etc. - at this level the access is restricted by the CanActivate guard - when trying to navigate to each component the roles of each admin-user is checked by the CanActivateChild guard.

提交回复
热议问题