相关疑难解决方法(0)

如何在Angular 2中为特定路由实现RouteReuseStrategy shouldDetach

我有一个Angular 2模块,我在其中实现了路由,并希望在导航时存储状态.用户应该能够:1.使用搜索公式搜索文档2.导航到其中一个结果3.导航回searchresult - 无需与服务器通信

这可能包括RouteReuseStrategy.问题是:如何实现不应存储文档?

那么应该存储路径路径"文档"的状态,并且不应存储路径路径"documents /:id"'状态?

javascript typescript angular-ui-router angular

85
推荐指数
7
解决办法
3万
查看次数

Angular2 Routing - 在路由更改时保持组件的状态

我有一个应用程序,路径后面的视图,我需要能够从路由更改时的点继续,但在返回后,组件处于其初始状态.

有没有办法如何保持组件的状态?

angular2-routing angular

19
推荐指数
1
解决办法
2万
查看次数

子模块中的RouteReuseStrategy

这是我的懒惰加载子模块:

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(acnpRoutes),
    ....
  ],
  declarations: [...],
  providers: [
    {provide: RouteReuseStrategy, useClass: ACNPReuseStrategy}
  ]
})
export class AddCustomerNaturalPersonModule {
}
Run Code Online (Sandbox Code Playgroud)

路线:

const acnpRoutes: Routes = [
  {
    path: '',
    component: AddCustomerNaturalPersonComponent,
    children: [
      {
        path: 'stepOne',
        component: ACNPStepOneComponent
      },
      {
        path: 'stepTwo',
        component: ACNPStepTwoComponent
      },
    ]
  }
]
Run Code Online (Sandbox Code Playgroud)

和ACPNReuseStrategy:

export class ACNPReuseStrategy implements RouteReuseStrategy {
  handlers: {[key: string]: DetachedRouteHandle} = {}

  shouldDetach(route: ActivatedRouteSnapshot): boolean  {
    console.log(1)
    return true;
  }

  store(route: ActivatedRouteSnapshot, handle: {}): void {
    console.log(2)
  } …
Run Code Online (Sandbox Code Playgroud)

routing angular

5
推荐指数
2
解决办法
1489
查看次数