1) Create new project
ng new angular-test
ng g component projects
ng g component typings
2) Add simple routing
/src/app/app.component.html
<router-outlet></router-outlet>
/src/app/app.module.ts
export const ROUTES: Routes = [
{
path: '',
redirectTo: '/projects',
pathMatch: 'full'
},
{
path: 'projects',
component: ProjectsComponent,
},
{
path: '/typings',
component: TypingsComponent
},
{
path: '**', redirectTo: ''
}
];
@NgModule({
declarations: [
AppComponent,
ProjectsComponent,
TypingsComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forChild(ROUTES)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
EXCEPTION: Error in ./AppComponent class AppComponent - inline template:3:0 caused by: No provider for RouterOutletMap!
ORIGINAL EXCEPTION: No provider for RouterOutletMap!
I tried to add RouterOutletMap to providers in AppModule, exception don't throw, but app don't redirect to projects and don't show nesting components
You need to call RouterModule.forRoot
for the app module, not forChild
. The former adds all the core providers, while the latter doesn't. You should use forChild
for child modules, not the app module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With