我想根据商店中的值实现路由器保护。如果用户登录到应用程序,我想获取该用户的角色并激活我的子模块路由的某些路由。
我将发布我当前的实现,但这根本不起作用
ps我没有使用角度路由器商店
canActivate(): {
return this.store.pipe(select(selectUser)).pipe(
skip(1),
map((user) => {
const userObj: any = user
if (userObj.userRole === "Admin") {
this.router.navigateByUrl('admin/tourprovider/genaral-infomation');
return true;
} else {
this.router.navigateByUrl('home')
return false;
}
})
)
}