I have a routing strategy that does not destroy the component when routing to another component. I would like to call a method of the component, when (re)routing to it.
Until now I've tried implementing the interfaces AfterContentChecked
and AfteViewChecked
with their respective methods ngAfterContentChecked
and `ngAfterViewChecked. The only problem with implementing one of this interfaces is that the method is called multiple times when routing to the component and this is a performance problem for me.
While researching the web I haven't come across an interface which I could implement in order to obtain the desired behaviour.
Is the only possibility for solving this, verifying in the router which route/path was selected and in the case of the desired one, I call the method of the component?
You can subscribe to the router's events, this will fire off an event each time your route changes. You can then get the active route of off this event and check if the route of the component you're currently in is equal to that route.
TIP: Filter on the events by using instanceof NavigationEnd