1

在我的 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_ComponentB_ComponentC_Component。因此,当用户导航到 时configurator/,会FooComponent显示A_ComponentSampleAction触发 。没关系。

但是:当用户从其中一个导航configurator/bconfigurator/c返回到configuratorSampleAction不应触发 。

我怎么能那样做?

4

0 回答 0