Reputation: 5095
I am using angular v5.
I have home component and home2 component
routing set up :
{
path: "home",
component: homecomponent
},
{
path:"home2",
component: home2component
}
{
path:"**",
redirectTo:"/home",
pathMatch: "full"
}
I am facing issue when redirect back to home component. home component complete reinitialise.
How to manage home component's state?
Upvotes: 0
Views: 1164
Reputation: 2397
Managing state is a hard problem. We need to coordinate multiple backends, web workers, and UI components, all of which update the state concurrently.
You can use Ngrx to manage State of a component in Angular 2+
This is the interaction between those components in NgRx:
There are five parts that constitute NgRx:
The Ngrx provides a single source of truth for the state of your application.
You can understand more about Ngrx here
Upvotes: 1
Reputation: 20132
That is normal behavior because when you visit your angular component Angular will trigger life cycle hook ngOnInit
to init the component
After you navigate away from your component component will get destroy using ngOnDestroy
to avoid memory leak.
Upvotes: 1