I have an app with angular 8 in which a have created two module:
- testModule and SimulatorModule
the simulator is having a routing file but the testModule doesn't.
I want to load all the component in the Simulator as children of the TestComponent found in TestModule.
But when I run the app expecting test component to be lunch, I'm always redirect to appComponent.
these are the code:
**//app.routing.ts**
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{
path: '',
redirectTo: 'simulator',
pathMatch: 'full'
},
{
path: 'simulator',
loadChildren: './simulator/simulator.module#SimulatorModule'
}
]
@NgModule({
imports: [
RouterModule.forRoot(routes, { scrollPositionRestoration: 'enabled' })
],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule {}
and
//simulator.routing.module
import { NgModule } from '@angular/core';
import { RouterModule, Routes, Route } from '@angular/router';
import { SimulatorPageComponent } from '@app/simulator/simulator-page/simulator-page.component';
import { Test } from '@app/test/test.service';
const routes: Routes = [
Test.childRoutes([
{
path: '',
component: SimulatorPageComponent
}
])
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: []
})
export class SimulatorRoutingModule { }
and
//Test.service
static childRoutes(routes: Routes): Route {
return {
path: '',
component: TestComponent,
children: routes,
data: { reuse: true }
};
}
who has an idea please of what is not going on!
I use it like below. Ofc, you might do it any other way.
Folder strukcute:
src/app/app-routing.module.ts
app.component.html
Because I use
loadChildren
, I need a component loading. So I need more "xy-routing.module.ts" in./default
,./foo
and./foo-bar
directories:For example
foo-routing.module.ts
what included intofoo.module.ts
.If you want to use
<router-outlet></router-outlet>
insrc/app/foo-bar/foo-bar.component.html
src/app/foo-bar/foo-bar-routing.module.ts