The first way. No children, no modules imported.
const routes: Routes = [
{path: '', pathMatch: 'full', redirectTo: 'group'},
{path: 'group/feature', component: FeatureComponent },
{path: 'group', component: GroupComponent},
{path: '**', component: PageNotFoundComponent}
];
@NgModule({
imports: [
RouterModule.forRoot(routes,
{enableTracing: false, useHash: false}
)
],
exports: [
RouterModule
]
})
export class AppRoutingModule {
}
The second way is to use children..
const routes: Routes = [
{path: '', pathMatch: 'full', redirectTo: 'group'},
{path: 'group', component: GroupComponent,
children: [
{ path: 'feature', component: FeatureComponent }]
},
{path: '**', component: PageNotFoundComponent}
];
The third way is to import the module. It has its own
"<router-outlet></router-outlet>".
const ingestRoutes: Routes = [
{ path: 'group/feature', component: FeatureComponent,
children: [
path: 'more', component: MoreComponent, // if you want to add..
// this will route to group/feature/more
path: '', component: FeatureHomeComponent,
]
}
];
@NgModule({
imports: [
RouterModule.forChild(ingestRoutes)
],
declarations: [
FeatureComponent, FeatureHomeComponent, MoreComponent
],
exports: [
RouterModule
]
})
export class GroupRoutingModule {
}
The FeatureComponent.html has only
<route-outlet></router-outlet>.
FeatureHomeComponent.html
- you can display anything here..YOUR ACTURE FEATURE COMPONENT.HTML
Export this in AppRoutingModule.
const routes: Routes = [
{path: '', pathMatch: 'full', redirectTo: 'group'},
{path: 'group', component: GroupComponent},
{path: '**', component: PageNotFoundComponent}
];
@NgModule({
imports: [
RouterModule.forRoot(routes, {enableTracing: false, useHash:
false}), GroupRoutingModule, // add this..
],
exports: [
RouterModule
]
})
export class AppRoutingModule {
}
All I do for 'apple brand' is to just import AppleRoutingModule in my AppRoutingModule. See link.Angular 4 route selection for category/subcategory or category/item for ecommerce web site