I am converting my Angular 4 application to Angular 6. However, I am facing issues while making the routing related changes.
Now when I run my application, Home component is loaded but the child component ContentsComponent
which has empty path is not loaded.
Routing in my application is defined like below:
app.routing.module.ts
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'support', component: SupportComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
home.routing.module.ts
const routes: Routes = [
{
path: 'home', component: HomeComponent,
children: [
{ path: '', component: ContentsComponent }, //<-- This component is not loaded
{ path: '**', redirectTo: 'home' }
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class HomeRoutingModule { }
home.module.ts
@NgModule({
imports: [
HomeRoutingModule
],
exports: [],
declarations: [ HomeComponent, ContentsComponent ],
providers: [],
})
export class HomeModule { }
app.module.ts
@NgModule({
imports: [
BrowserModule,
AppRoutingModule,
ReactiveFormsModule,
HomeModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy }
]
})
export class AppModule { }
home.component.html
<router-outlet></router-outlet>
EDIT: Please note that I don't want to display anything after the /home
url part.