i have created many modules which has internal components
folder strutcure
--app
--java
--Introduction
--Syntax
each of them is a component , and i have added routing module to all components .
now if i add children route to app.routing.ts , it is routing correctly. but when i add child routes to different routing module ,it does not route to that component and gives error :
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'JAVACourse/Syntax'
following below are some of my codes :
1.app.routing.ts
i have commented the children routes as this is working.
const appRoutes: Routes = [
{path:'Home' , component: HomepageComponent },
{path:'JAVACourse' , component: JavaComponentComponent },
// children: [
// { path: 'Introduction',component:IntroductionComponent},
// { path: 'Syntax', component: SyntaxComponent },
// ]
// }
{path:'HTMLCourse' , component: HtmlcomponentComponent },
{path:'ASP.NET' , component: DotnetcomponentComponent },
// {path: '', redirectTo: '/Home',pathMatch: 'full'},
//{path: '**',redirectTo: '/Home',pathMatch: 'full' }
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes
)
],
exports: [
RouterModule
],
providers: [
]
})
In my main component i have many horizontal navbar tab i.e Java Tab which routes to sidenavbar with child tabs.
2.javacomponent.html
<ul>
<a>JAVA Course</a>
<li routerLinkActive="active"[routerLinkActiveOptions]="{exact: true}"><a routerLink="Introduction">Introduction</a></li>
<li routerLinkActive="active"><a routerLink="Syntax">Syntax</a></li>
</ul>
java.routing.ts
const JavaRoutes: Routes = [ {path:'JAVACourse' , component: JavaComponentComponent , children: [ { path: 'Introduction',component:IntroductionComponent}, { path: 'Syntax', component: SyntaxComponent } ]}
];
@NgModule({ imports: [ RouterModule.forChild(JavaRoutes) ], exports: [ RouterModule ] })
4.Java.module.ts
@NgModule({
imports: [
JavaRoutingModule
],
declarations: [
IntroductionComponent,
SyntaxComponent
],
providers: [ ]
})
export class JavaRoutingModule {}