Search code examples
angularrouter-outletngoninit

Detect navigation back from component in named router outlet


I display an A Component in a router-outlet and inside this I have another B Component which has a named router-outlet, where I display another C component.

Router-outlet
A Component
    B Component
    Named Router-outlet
        C Component

In this C Component, I perform a validation, after this, I want to go back into the A Component reloading it (executing ngOnInit or any method).

I have tried it using different methods, like navigate, navigateByUrl and Location.back(). The problem is that the A Component is never destroyed, therefore it's never executed the ngOnInit method.

Somebody know how can I solve this? Thanks!


Solution

  • I'm not quite sure how you'll be able to execute the ngOnInit again, but a workaround could be to subscribe to router events (as described here) and execute the code you want in there.