In my application I have a SupportModule
which has 3 sub-Modules (AdminModule
,ChatModule
,ContactModule
). SupportModule
and its 3 sub-Modules have their own routings define.
Structure looks something like
The routing for the `AdminModule' is given below:
import { AdminComponent } from './admin.component';
import { RssFeedsComponent } from './rssFeeds.component';
import { RssFeedDetailComponent } from './rssFeedDetail.component';
export const adminRoutes: Route =
{
path: 'admin',
component: AdminComponent,
children: [
{ path: '', component: RssFeedsComponent },
{ path: 'feeds', component: RssFeedsComponent },
{ path: 'feeddetail', component: RssFeedDetailComponent }
]
};
and routing for SupportModule
(which is parent module of the 3 sub modules) is given below:
import { SupportComponent } from './support.component';
import { SupportNavComponent } from './support-nav.component';
//Feature Modules
import { chatRoutes } from './chat/chat.routing';
import { contactRoutes } from './contact/contact.routing';
import {adminRoutes} from './admin/admin.routing';
const supportRoutes: Routes = [
{
path: 'support',
component: SupportComponent,
children: [
{ path: '', component: SupportNavComponent },
chatRoutes,
contactRoutes,
adminRoutes
]
}
];
export const supportRouting: ModuleWithProviders = RouterModule.forChild(supportRoutes);
Then finally I am importing this supportRouting
into my AppModule
.
Navigation is working fine without any issue. But I am a little confused. I don't know whether this is the right way to have parent-child modules with their own routing or if there is some better way to achieve this.
If someone can correct me (if I am making a mistake) or knows a better approach then that would be really helpful.