angular - 来自特定路由时不要执行 Nx 的路由导航
问题描述
在我的 Angular 应用程序中,我使用 NgRx 和 Nx 的路由器导航:
@Effect() navigation$ = this.dataPersistence.navigation(A_Component, {
run: (a: ActivatedRouteSnapshot) => {
const id = a.params.id;
if (id) {
return new SampleAction(State.VIEW, id);
} else {
return new SampleAction(State.NEW);
}
},
onError: (a: ActivatedRouteSnapshot, e: any) => {
console.error(e);
return null;
},
});
我的路线定义如下:
// ...
RouterModule.forChild([{
path: 'configurator',
component: FooComponent,
canActivate: [AuthGuard],
children: [{
path: '',
component: A_Component
}, {
path: 'b',
component: B_Component,
}, {
path: 'c',
component: C_Component,
}, ],
},
{
path: '',
pathMatch: 'full',
redirectTo: 'configurator'
},
]),
// ...
FooComponent
有一个<router-outlet></router-outlet>
来显示三个组件之一A_Component
,B_Component
或C_Component
。因此,当用户导航到 时configurator/
,会FooComponent
显示A_Component
并SampleAction
触发 。没关系。
但是:当用户从其中一个导航configurator/b
或configurator/c
返回到时configurator
,SampleAction
不应触发 。
我怎么能那样做?
解决方案
推荐阅读
- php - PHP 使用时间戳作为常量
- javascript - 如何修复 TypeError:无法读取未定义的属性“长度”?节点
- json - 有没有更好的方法让我在 PowerShell 中循环遍历 json 节点
- postgresql - PostgreSQL / psql 元命令静默失败并且不插入行
- spring-boot - AWS ElasticCache Redis 的 Spring Data 随机变慢,用户负载较高
- encryption - 使用变量函数创建哈希值
- python - 解释 RollingOLS 预测输出
- python - 在删除 NaN 值的同时跨行合并 DataFrame
- python - 在python中组合数据框但避免重复
- scala - 将 GraphX 数据保存到 Spark 的块管理器中