Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @NgModule({
- imports: [
- CommonModule,
- RouterModule.forChild(acnpRoutes),
- ....
- ],
- declarations: [...],
- providers: [
- {provide: RouteReuseStrategy, useClass: ACNPReuseStrategy}
- ]
- })
- export class AddCustomerNaturalPersonModule {
- }
- const acnpRoutes: Routes = [
- {
- path: '',
- component: AddCustomerNaturalPersonComponent,
- children: [
- {
- path: 'stepOne',
- component: ACNPStepOneComponent
- },
- {
- path: 'stepTwo',
- component: ACNPStepTwoComponent
- },
- ]
- }
- ]
- 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)
- }
- ...
- shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
- console.log(5)
- }
- }
- navigate to a
- shouldReuseRoute->return true->do nothing
- a->b
- shouldReuseRoute()->return false->shouldDetach()->return true->store a
- then b->a
- shouldReuseRoute()->return false->shouldDetach()->return true->store b->retrieve() return a ->attach() a.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement