CanActivate vs. CanActivateChild with component-less routes

后端 未结 6 1150
傲寒
傲寒 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:35

    One reason I can think of is timeouts.

    I'm starting to work with Angular 2, using an authentication provider. This provider expires a session which has been idle for more than a certain amount of time.

    In a common situation where you leave your computer logged in and your session expires, the next navigation you try MUST validate your current situation. If you are navigating between child routes, I think CanActivateChild is the guard that will detect the expired session, and trigger a redirect to login, while CanActivate won't trigger at all.

    Disclaimer: This came from the top of my head, I haven't implemented it yet.

提交回复
热议问题