- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 Angular 2.0.1(最终版)应用,它使用 HashLocationStrategy 作为路线导航策略。
我定义了一条路线如下:
{
path: 'shiftmanage', component: ShiftManageComponent,
canLoad: [AuthGuard],
canActivate: [AuthGuard]
},
这是 AuthGuard 类:
import { Injectable } from '@angular/core';
import {
Route,
Router,
CanLoad,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot } from '@angular/router';
@Injectable()
export class AuthGuard implements CanLoad, CanActivate {
constructor(private router: Router) {
console.log("AuthGuard constructor")
}
canLoad(route: Route): boolean {
if (route.path === "shifts") {
return true;
} else {
return false;
}
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if (route.routeConfig.path === "shiftmanage") {
return true;
} else {
return false;
}
}
}
然后我将这个保护类添加到 NgModule Provider 中,如下所示:
providers: [
AuthGuard,
{ provide: LocationStrategy, useClass: HashLocationStrategy }
... other providers
]
导航正常,每当我尝试导航到 shiftmanage 路径时,canActivate 路由守卫就会被触发。
问题 canLoad 路由守卫从未被击中。
这个 canLoad 守卫是否因为 HashLocationStrategy 而没有被击中,还是我做错了什么?
最佳答案
canLoad
用于加载lazy-loaded modules使用 loadChildren
{
path: 'child',
canLoad: [AuthGuard],
loadChildren: 'path/to/child.module'
}
关于angular - 为什么路由守卫 canLoad 不开火,但 canActivate 开火,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40011143/
我使用 django celery 和 rabbitmq 作为我的经纪人( guest 兔子用户在本地机器上具有完全访问权限)。我有一堆项目都在他们自己的 virtualenv 中,但最近其中 2 个
我正在 Angular 中构建一个守卫,我需要在其中发出两个不同的 HTTP 请求,并根据这两个请求来确定是否继续。我注意到 forkJoin 是执行此操作的正确方法,但我无法触发。 在我的代码中,我
我刚刚下载了 openfire 3.10。 安装正常。但是当我启动 Openfire 服务器时,它在启动过程中出现以下错误: java.lang.IllegalArgumentException: I
我正在构建一个网络聊天应用程序。我想在每次按下“输入”按钮后存储两方之间的消息或对话。我正在使用 Openfire 服务器和 MySQL 数据库。我没有从存储对话的数据库中看到任何表格。 有插件吗?谢
我有一个 Vue 组件,我需要 body 元素有 overflow:none 但其余页面应该有 overflow:auto。因为正文位于组件外部,所以组件内的作用域 css 不会应用于正文。我的解决方
我有一个 Angular 2.0.1(最终版)应用,它使用 HashLocationStrategy 作为路线导航策略。 我定义了一条路线如下: { path: 'shiftmanag
我是一名优秀的程序员,十分优秀!