'Is it possible to persist Angular 13 Component-Objects in Memory?

  • In my architecture, I'm using a routing main-component, to switch between sections of my app in which I use single components.

  • Also, I have one component in the main-component which stays in 'foreground' all the time and which is needed to be used in combination with the components of the other sections.

  • For communication between the 'fixed' component and the other components, I am using a subsciption to the topics of the fixed component.

  • Now: when switching through the sections via the routing module, the lifetime of the switchable components is over; their OnDestroy-Methods are getting called (the subscriptions get canceled.)

  • When an Event happens, while the other component is not created (which is the case when the user views another route), it can't receive the events.

  • In my use case it should be possible to trigger an event in the 'fixed' component, which then triggers the router to be switched to the correct routing-path and get the 'switch'-component-object. This object also needs the information, which the fixed component sent.

  • I hope, my explaination is thorough and understandable (also see the attached draft), I'm relatively new to angular and web programming in genereal .

  • Now I stumbled upon the Angular RouteReuseStrategy but I'm afraid it won't help, as it kind of 'recreates' a saved state of the before-visited route and the components behind it are 'inactive' and can't receive events either.

Does anyone has a hint for me? Maybe my concept needs a makeover.

enter image description here

Greets, Che



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source