關于Angular路由中CanActivateChild鉤子的用法
CanActivateChild 和CanActivate的用法如出一轍,使用對象可能有所不同,例如說CanActivate一般的使用對象要么是兄弟平級關系,而CanActivateChild主要用在父類路由中用于在激活子路由之前進行權限驗證或其他操作。
具體使用實例:
const routes: Routes = [
{ path: 'home', component: HomeComponent,canActivateChild:[loginGuradsGuard] ,
children:[
{ path: 'indexs', component: IndexsComponent }
]
},
];
使用步驟與上一篇一樣,首先用指令創建路由守衛,ng g guard guard/auth(名字)之后使用指令 ng g component components/header 創建組件 后面在路由文件中配置路由信息即可

浙公網安備 33010602011771號