Angular route error: "A router outlet has not been instantiated during routes activation"

Viewed 3836

I'm getting it for any route. What is this warning and how to fix it? All the routes working fine BTW.

1 Answers

I was facing the same issue since the Angular 10.1 update, posting the fix that worked for me for future google searches of others.

Turns out the error had nothing to do with the components on the mentioned route, but with the components navigating to this route.

Multiple components were navigating the router, and I tested this navigation with the following code:

spyOn(component.router, 'navigate').and.callThrough();

This actually calls the navigation, but that's not necessary. A mocked resolve of the navigate promise is enough. New version:

spyOn(component.router, 'navigate').and.resolveTo();

And all the warning disappeared.

Related