简体   繁体   中英

Angular 2 router fails to reuse same Component instance when navigating to same route with different params

According to the Angular 2 docs :

By default, the router reuses a component instance when it re-navigates to the same component type without visiting a different component first. The parameters can change between each re-use

I need help figuring out why this does not work on my lazy-loaded routes. To reproduce:

  • Open this plunker
  • On LazyLoadedComponent press Next ID button to trigger navigation to the same route (new param). Notice that the component is destroyed and a new instance is initialized each time.

在此输入图像描述

  • On HomeComponent , things work as expected. Triggering navigation executes the ActivatedRoute.params.subscribe() callback but the component is not re-initialized

在此输入图像描述

I'm using Angular 2 rc.5 and Angular Router 3 rc.1 Why does my lazy-loaded component not behave in accordance with the docs?

This is an Angular bug. It has been reported and the next version should be fixed. See https://github.com/angular/angular/pull/10707

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM