Description
This problem is mentioned in #374 but can't find any solution of it.
So the problem is, for example, I have two Component: HomeComponent and AboutComponent
In HomeComponent.html a link [nsRouterLink]="['/about']"
can route to AboutComponent.
In AboutComponent.html a link [nsRouterLink]="['/home']"
can route back to HomeComponent.
When the app start, home component shows, if I:
- click about link to go to About page, HomeComponent instance H1 cached, AboutComponent instance A1 created
2.1 if I click back button in android or IOS, H1 shows, no new Home instance created
2.2 if I click home link in about page , however, a new H2 instance created, and old H1 still exist.
My concern about this problem is:
- step 2.2 would lead to memory leak!
- something it is necessary to provide user a button or link to route to another component, but behavior between user router link/button and device back button are difference: one use old instance and one create new. developer have to pay much works to deal with the problem caused by this difference.
I am not sure if navigate via [nsRouterLink] or router.navigate(['/...']) to an cached component causing an new instance created is a bug,
I think, if there is a way to let [nsRouterLink] or router.navigate(['/...']) to reuse cached component instance, that could workaround the problem. and I just use Page.unloadedEvent and Page.loadedEvent to trigger ngOnDestroy and ngOnInit to keep a singleton instance working.