I have multiple modules in angular app, which I load lazily. Every module has its own routing.
My top level routing
const appRoutes: Routes = [
{
path: "module1",
loadChildren: "app/components/m1.module#MOduleOne"
},
{
path: "module2",
loadChildren: "app/components/m2.module#ModuleTwo"
},
{
path: "**",
redirectTo: "module1"
}
];
In my ModuleTwo
import { NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";
import { routes } from "./m2.routes";
import { AComponent } from "./a.component";
import { BComponent } from "./b.component";
import { CComponent } from "./c.component";
const components = [AComponent, BComponent,CComponent];
@NgModule({
declarations: components,
exports: components,
imports: [RouterModule.forChild(routes)]
})
export class ModuleTwo { }
routing file
import { Routes } from "@angular/router";
import { AComponent } from "./a.component";
import { BComponent } from "./b.component";
import { BComponent } from "./c.component";
export const routes: Routes = [
{
path: "",
component: AComponent,
children: [
{
path: "b",
component: BComponent
},
{
path: "c",
component: CComponent
}, {
path: "**",
component: BComponent
}
]
}
];
a.component.html
<div>
Hi
<router-outlet></router-outlet>
</div>
and b.component.html
<div>
<div routerLink="/b">
<i class="material-icons">local_shipping</i>
<span>B</span>
</div>
<div routerLink="/c">
<i class="material-icons">file_download</i>
<span>C</span>
</div>
</div>
Now on my http://localhost:4200/#/a
, component a is loaded with b as child component.
But when i click the icons that redirects to /b
and /c
, it does not work and reload the page to the ModuleOne
.
What can be the issue?
Update 1
I tried /b
instead of b
in path in route.ts
.
Even If hit directly the URL http://localhost:4200/#/a/c
, this just show the default page that is b component only.