Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. @NgModule({
  2. imports: [
  3. CommonModule,
  4. RouterModule.forChild(acnpRoutes),
  5. ....
  6. ],
  7. declarations: [...],
  8. providers: [
  9. {provide: RouteReuseStrategy, useClass: ACNPReuseStrategy}
  10. ]
  11. })
  12. export class AddCustomerNaturalPersonModule {
  13. }
  14.  
  15. const acnpRoutes: Routes = [
  16. {
  17. path: '',
  18. component: AddCustomerNaturalPersonComponent,
  19. children: [
  20. {
  21. path: 'stepOne',
  22. component: ACNPStepOneComponent
  23. },
  24. {
  25. path: 'stepTwo',
  26. component: ACNPStepTwoComponent
  27. },
  28. ]
  29. }
  30. ]
  31.  
  32. export class ACNPReuseStrategy implements RouteReuseStrategy {
  33. handlers: {[key: string]: DetachedRouteHandle} = {}
  34.  
  35. shouldDetach(route: ActivatedRouteSnapshot): boolean {
  36. console.log(1)
  37. return true;
  38. }
  39.  
  40. store(route: ActivatedRouteSnapshot, handle: {}): void {
  41. console.log(2)
  42. }
  43.  
  44. ...
  45.  
  46. shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
  47. console.log(5)
  48. }
  49. }
  50.  
  51. navigate to a
  52. shouldReuseRoute->return true->do nothing
  53.  
  54. a->b
  55. shouldReuseRoute()->return false->shouldDetach()->return true->store a
  56.  
  57. then b->a
  58. shouldReuseRoute()->return false->shouldDetach()->return true->store b->retrieve() return a ->attach() a.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement