-
-
Notifications
You must be signed in to change notification settings - Fork 241
How to reuse cached component when routing to it? #1440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@liuwei108 The answer to your question about step 2.2. is well explained here (the difference between navigation back and navigation forward even if you are navigating to the very same page in cases like |
Hello NickIliev, Thank for reply. I saw the explanation in there. I understand this behavior is by design and may match many scenario. Currently I can workaround by: Kindly please let me know if above options are feasible, or if you have better idea. Thanks Regards, |
@luiwei108 can u provide us sample code of the workaround. Thanks |
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:
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:
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.
The text was updated successfully, but these errors were encountered: