Although @JS_astronauts already provided a solution, I think it would be instructive to explain the error ...
The main output is set when Angular parses the HTML template and finds the RouterOutlet directive , i.e. when it finds the RouterOutlet selector: <router-outlet></router-outlet> .
Although your template contains <router-outlet></router-outlet> , your component does not contain directives: [ROUTER_DIRECTIVES] , so Angular will not look for any of the directives defined by this constant:
export const ROUTER_DIRECTIVES = [RouterOutlet, RouterLink, RouterLinkWithHref, RouterLinkActive];
Therefore, when Angular parses AppComponent HTML templates, if it does not recognize <router-outlet></router-outlet> , so it just ignores it. Later, when Angular tries to display the default route component (HomePage), it complains because it does not know where to put it.
This error may also occur if you have a typo in the element selector, for example:
<roter-outlet></roter-outlet>
In this case, even if your directives array is set correctly, Angular will never find the required <router-outlet> element.
Mark Rajcok Jul 09 '16 at 16:55 2016-07-09 16:55
source share