我有一个Angular 2模块,我在其中实现了路由,并希望在导航时存储状态.用户应该能够:1.使用搜索公式搜索文档2.导航到其中一个结果3.导航回searchresult - 无需与服务器通信
这可能包括RouteReuseStrategy.问题是:如何实现不应存储文档?
那么应该存储路径路径"文档"的状态,并且不应存储路径路径"documents /:id"'状态?
我有一个应用程序,路径后面的视图,我需要能够从路由更改时的点继续,但在返回后,组件处于其初始状态.
有没有办法如何保持组件的状态?
这是我的懒惰加载子模块:
@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)