How to apply canActivate guard on all the routes?

前端 未结 3 1396
慢半拍i
慢半拍i 2020-12-12 20:29

I have a angular2 active guard which handle if the user is not logged in, redirect it to login page:

import { Injectable } from  \"@angular/core\";
import {          


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 21:02

    I think you should implement "child routing" which allow you to have a parent (with a path "admin" for example) and his childs.

    Then you can apply a canactivate to the parent which will automatically restrict the access to all his child. For example if I want to access "admin/home" I'll need to go throught "admin" which is protectected by canActivate. You can even define a parent with an empty path "" if you want

提交回复
热议问题