4

I implemented a custom route strategy (more or less copied, see here) to cache already visited routes. Now I want to detect if a component inside a cached route has been reattached or detached.

For example: I want to resume a video inside a component if a cached route has been reattached.

Basically I can compare the route on which it has been initialized and subscribe to route changes. But I am currently struggling on how to implement this the best possible way because this seems to be implemented in every component.

I was looking for Lifecycle Hook methods but it seems that none of them are executed on my route strategy.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JanMod
  • 364
  • 2
  • 9
  • An idea: Use a subject in your custom strategy and when the `retrieve` method is called, make that subject emit a new value with the component that you're interested in. You can get that component by searching in it `ActivatedRouteSnapshot`. – Andrei Gătej Nov 20 '20 at 07:26
  • But I need to know the component inside my route strategy. – JanMod Nov 20 '20 at 09:22
  • I could iterate through every child component and emit an event. Is it possible? – JanMod Nov 20 '20 at 09:28
  • Yes, try to `console.log` the `ActivatedRouteSnapshot`. – Andrei Gătej Nov 20 '20 at 10:13

0 Answers0