Update
I changed forRoot with forChild according to the answers.
So, basically I have to issues, let this be a submodule,
@NgModule({
imports: [
CommonModule,
ARoutingModule,
BModule
],
declarations: [AppsComponent, ...],
exports: [
AppsComponent, ...
]
})
export class AModule { }
and
@NgModule({
imports: [
CommonModule,
BRoutingModule
],
declarations: [AppsComponent, ...],
exports: [
AppsComponent, ...
]
})
export class BModule { }
So AModule is being imported by the root module and both modules, AModule and BModule shall define their own routes, something like
// ./A/A-Routing.module.ts
const routes: Routes = [
{
path: 'A',//<-- this shall route to www.site.com/A
component: AComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: []
})
export class ARoutingModule { }
and in SubSub I have
// ./A/B/B-Routing.module.ts
const routes: Routes = [
{
path: 'B', //<-- this shall route to www.site.com/A/B
component: BComponent,
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: []
})
export class BRoutingModule { }
Is this possible? When using a path printing, I can get the sub-routes, but not the subsub routes (i.e. B). And can I define the routes in B without knowing the path before that? so define B without knowing A
www.site.com/something/else
define routes for else without knowing something?
Here is a stackblitz example, main works, but the Subs don't...
RouterModule.forRoot([])is used for routing only in the root module of the application. For using routes in other modules, useRouterModule.forChild([])