首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Child guard: canActivateChild不工作

Child guard: canActivateChild不工作
EN

Stack Overflow用户
提问于 2017-02-26 19:19:28
回答 2查看 9.7K关注 0票数 7

我试着安排一个像angular doc那样的儿童保护:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@Injectable()
export class AuthGuardService implements CanActivate, CanActivateChild {

  constructor(private authService: AuthentificationService, private router: Router) {}

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    let url: string = state.url;

    return this.checkLogin(url);
  }

  canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    return this.canActivate(route, state);
  }

  checkLogin(url: string): boolean {
    /*****/
    return false;
  }
}

我的routing.module:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import { AuthGuardService } from '../services/auth-guard.service';

const routes = [
    {
        path: '',
        component: MyComponent,
        canActivate: [AuthGuardService],
        children: [{
            path: '',
            canActivateChild: [AuthGuardService],
            children: [
                {
                    path: 'candidature',
                    component: ListCandidatureComponent,
                },
                {
                    path: 'candidature/new',
                    component: NewCandidatureComponent
                }]
        }, {
            path: 'login',
            component: LoginComponent,

        }]
    }
]

我将我的canActivateChild保护放在无组件部分,通过身份验证来保护这个路由。

但在这种配置下,当我试图访问'my.site.com/candidature‘时,我得到了这个错误:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Unhandled Promise rejection: guard is not a function ; Zone: angular ; Task: Promise.then ; Value: TypeError: guard is not a function

通常,如果我没有通过身份验证,我需要被重定向到登录页面。有没有人知道这个错误,或者知道为什么要用午餐?

感谢‘s

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-02-28 08:56:04

如果找到我的解决方案。我为其他有同样问题的人解释。

与excepted一样,routing-module是子路由模块这一事实会引发此错误。我需要在de AppRouting中提供要用于子舍入模块的AuthGuardService,如下所示:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@NgModule({
    imports: [
        RouterModule.forRoot(routes)
    ],
    exports: [RouterModule],
    declarations: [],
    providers: [AuthGuardService] //Here add the AuthGuardService to be available in route-module-child
})
export class AppRoutingModule {}
票数 4
EN

Stack Overflow用户

发布于 2017-02-27 09:40:14

canActivateChild: [AuthGuardService],不应位于children内部,而应在父路由中声明。

不是很确定,当你声明了子级中的子级时,你也需要在外部的子级中声明canActivateChild。但是您可以使用它或不使用它进行测试。如果有效,请让我知道!

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
const routes = [
    {
        path: '',
        component: MyComponent,
        canActivate: [AuthGuardService],
        canActivateChild: [AuthGuardService] // it should be placed here!
        children: [{
            path: '',
            // canActivateChild: [AuthGuardService], // needed or not?
            children: [
                {
                    path: 'candidature',
                    component: ListCandidatureComponent,
                },
                {
                    path: 'candidature/new',
                    component: NewCandidatureComponent
                }]
        }, {
            path: 'login',
            component: LoginComponent,

        }]
    }
]

希望这能有所帮助!

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42473026

复制
相关文章
[周末往期回顾]Oracle Data Guard 工作流程
从这期开始讲Oracle Data Guard方面的内容,先将基本的概念,然后介绍如何搭建Data Guard
bsbforever
2020/08/19
2740
[周末往期回顾]Oracle Data Guard 工作流程
Oracle Data Guard 工作流程
从这期开始讲Oracle Data Guard方面的内容,先将基本的概念,然后介绍如何搭建Data Guard
bsbforever
2020/08/19
4820
Oracle Data Guard 工作流程
Angular 从入坑到挖坑 - 路由守卫连连看
Angular 入坑记录的笔记第六篇,介绍 Angular 路由模块中关于路由守卫的相关知识点,了解常用到的路由守卫接口,知道如何通过实现路由守卫接口来实现特定的功能需求,以及实现对于特性模块的惰性加载
程序员宇说
2020/06/04
3.8K0
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstati
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstati 搜索控制面板   找到卸载页面 启用或关闭Windows功能   关闭 Hyper-V 然后重启电脑即可
韩旭051
2022/05/09
9900
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstati
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstati
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstation。有关更多详细信息,请访问 http://www.vmware.com/go/turnoff_CG_DG。
walterlv
2023/10/22
2.2K0
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstati
[Data Guard全解析]3.Oracle Data Guard 工作流程
从这期开始讲Oracle Data Guard方面的内容,先将基本的概念,然后介绍如何搭建Data Guard
bsbforever
2020/08/19
5090
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstati
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstati(100%解决)
红目香薰
2022/11/29
2.9K0
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstati
VMware Workstation 与 Device/Credential Guard 不兼容.在禁用 Device/Credenti
虚拟机打开出错:VMware Workstation 与 Device/Credential Guard 不兼容.在禁用 Device/Credenti。。。。。。
互联网-小阿宇
2022/11/21
4.5K0
VMware Workstation 与 Device/Credential Guard 不兼容.在禁用 Device/Credenti
Windows凭据不工作
如果不是敲错IP、用户名、密码,报凭据不工作,一般情况下执行这几句命令后重启远程服务就正常了
Windows技术交流
2021/06/15
6.1K0
Swift guard
guard是 swift 2.0推出的新的判断语句的用法。guard语句和if语句类似,都是根据关键字之后的表达式的布尔值决定下一步执行什么。和if语句不同的是,guard语句只有一个代码块,而if语句可有多个代码块。(如 if 、else if、 else) 那么guard到底是什么作用呢?顾名思义,guard是作为保卫作用而存在的。当你不满足我的要求,那么请您出去;如果满足,则执行下一步操作。
赵哥窟
2020/08/11
9350
解决VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Devic..报错
VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credential Guard 后,可以运行 VMware Workstation。
非著名运维
2022/06/22
9.8K1
解决VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Devic..报错
详解:last-child first-child 5
核心:first-child:第一个,所在元素的哦 last-child:最后一个,所在元素的哦
贵哥的编程之路
2020/10/28
5120
Angular2 之 路由与导航基础知识路由模块组件路由路由守卫
最开始的路由,我们是直接写在app.module.ts文件中的,像这样,我们可以实现简单的导航。
贺贺V5
2018/08/21
3.3K0
The GNU Privacy Guard
对比《连城诀》,第一步是「唐诗选辑」(不过用口水解密不够文雅),第二部是「唐诗剑法」(没有师傅认证亲传武功是不行的),最后才解密出「江陵城南偏西天宁寺大殿佛像向之虔诚膜拜通灵祝告如来赐福往生极乐」。 当然也有类似凌退思这样“密码字典暴力破解”的方法 :-) 所以我们的 GPG 钥匙长度要设置的长长长一些。
筱竼
2022/08/09
4.8K0
The GNU Privacy Guard
RDP你的凭据不工作/RDP密码不刷新
如果你不属于上述的情况,请查看:https://learn.microsoft.com/zh-cn/windows-server/remote/remote-desktop-services/troubleshoot/rdp-error-general-troubleshooting#check-whether-a-group-policy-object-gpo-is-blocking-rdp-on-a-local-computer
阿龙w
2022/12/02
12.7K0
RDP你的凭据不工作/RDP密码不刷新
C++之include guard
有时候,我们在大的软件项目中需要避免一个头文件被同一个源文件引用多次,这个时候就需要用到include guard这个头文件保护符。
灯珑LoGin
2022/10/31
5150
child-selector解释
这个伪类选择器应该叫孩子选择器,意思是选择网页中所有父节点的第一个子节点,并且这第一个子字节点必须是指定标签元素 写法有 :first-child :last-child :nth-child(odd) :nth-child(even) :first-child解释: 1 <div class="sidebar"> 2 <p>1</p> 3 <p>2</p> 4 </div> 5 <div class="main"> 6 <a>3</a> 7
用户1749219
2018/05/16
8270
128 天不上班不工作:照样领工资 9.5 万
原告:北京和风畅想科技有限公司 被告:杜某,男,1988年出生 和风畅想公司向法院提出诉讼请求: 1、判决无须撤销《解除劳动关系通知书》,双方无需继续履行劳动合同; 2、判决和风畅想公司无须向杜某支付自2020年2月29日至2020年7月5日期间工资收入损失95172.41元。 事实和理由: 2020年11月2日,和风畅想公司收到北京市朝阳区劳动人事争议仲裁委员会作出的京朝劳人仲字[2020]第16281号裁决书(以下简称“第16281号裁决书”),和风畅想公司不服该裁决。 不服裁决理由: 一、第1628
云头条
2022/10/09
2.2K0
128 天不上班不工作:照样领工资  9.5 万
使用Data Guard Broker进行Data Guard物理备用库配置
本文讲解在Oracle Database 19c中使用Data Guard Broker进行Data Guard物理备用库配置。
Yunjie Ge
2022/04/24
8850
手工搭建Data Guard
Data Guard的搭建可以使用GC图形化安装,优缺点很明显,优点就是图形化操作,符合国人的习惯(据secooler介绍外国程序员能用图形化做的事就一定用图形做,因为boss看得懂,和国人正相反。。。),缺点就是如同Windows一样,宛如黑盒,换句话说,要时刻祈祷不要出问题,否则有时很难知道他为什么挂了。。。
bisal
2019/01/29
7560

相似问题

Angular 4 CanActivateChild不工作

05

CanActivateChild不运行

21

具有延迟加载模块路由的Angular 2 Routing Guard CanActivateChild

20

jquery child()不工作

25

:nth-child不工作

20
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文