If you created a separate module (eg. AppRoutingModule
) to contain your routing commands you can get this same error:
Error: StaticInjectorError(AppModule)[RouterLinkWithHref -> Router]:
StaticInjectorError(Platform: core)[RouterLinkWithHref -> Router]:
NullInjectorError: No provider for Router!
You may have forgotten to import it to the main AppModule
as shown here:
@NgModule({
imports: [ BrowserModule, FormsModule, RouterModule, AppRoutingModule ],
declarations: [ AppComponent, Page1Component, Page2Component ],
bootstrap: [ AppComponent ]
})
export class AppModule { }