Angular2 - ngOnDestroy () is not called on a similar route

I have an Angular2 application with this route:

{
  path: '',
  component: ContentComponent,
  children: [
    {
      path: 'folder/:folderId',
      resolve: {              
        currentFolder: CurrentFolderResolver,
      },
      children: [
        {
          path: '',
          resolve: {
            folderStructure: FolderStructureResolve,
          },
          component: FolderOverviewComponent,
        },
        {
          path: 'users',
          component: UsersComponent,
        }
      ]
    }
  ]
}

When navigating from a route, for example / folder / 123 to / folder / 456, Angular will not start ngOnDestroy()at FolderOverviewComponent. Navigation in / folder / 456 / users will be performed.

In other words, it seems that Angular does not destroy the component if the route does not change (ignoring the dynamic part: folderId). This seems reasonable, however I need to clean things up ngOnDestroy().

Can I configure routes for destruction every time I switch to a new route (i.e. with a different parameter)?

+4
source share
1 answer

. , , , .

params, :

constructor(router: ActivatedRoute) {
  router.params.subscribe(param => routeChanged(param['folderId']));
}

, .

. https://angular.io/guide/router#activated-route-in-action

+4

Source: https://habr.com/ru/post/1661200/


All Articles