Angular: How to get component instance of router-outlet

Don't try to use RouterOutlet as a provider. Instead add the (activate) attribute to your router-outlet tag like this:

<router-outlet (activate)="onRouterOutletActivate($event)"></router-outlet>

And then in the component containing the router-outlet element (your AppComponent class) you should implement the onRouterOutletActivate method:

public onRouterOutletActivate(event : any) {
    console.log(event);
}

which will give you the route component instance in the event parameter, in this example written to the web console.


to get the RouterOutlet instance, the following worked for me..

<router-outlet
  #foo="outlet"
></router-outlet>
@ViewChild( 'foo' )
foo: RouterOutlet;

https://angular.io/api/router/RouterOutlet#template-variable-references