在我的 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
不应触发 。
我怎么能那样做?