Reputation: 1040
We recently upgraded our angular2 application from 2.0.0-beta.15
to 2.0.0-rc.5
(including the migration to the new router 3.0.0-rc.1
). With a menu on the left and a sub-menu on the top of the page, our application has two <router-outlet>
at the same time.
Chasing some different behavior after the update, I noticed that any component in our application now (after the update) gets destroyed and constructed, even if the component is outside the <router-outlet>
. This was not the case with the old router. It's like the new router cannot reuse the already existing component.
I forked angular's CrisisCenter
into a plunker and added some simple debug console output to every components constructor to verify that this is due to the new version and not to configuration. The behaviour is the same: count
will never increase since the components are never reused. Does anybody have an idea how to reuse instances of component?
Aside, could anybody explain why the new router doesn't want to reuse components? I already came across CanReuse
from @angular/router-deprecated
, but this feature hasn't yet arrived for the new router. But even if CanReuse
was there for the new router, wouldn't it make more sense to reuse components by default instead of implementing CanReuse
for all "static" components? Or shouldn't components be reused at all?
Upvotes: 2
Views: 1461
Reputation: 657338
Sounds like you are running into this issue https://github.com/angular/angular/issues/10702 which is already fixed and will be included in the next update.
Upvotes: 2