Even though I'm relatively new with Angular this should be so simple that it's driving me crazy. I created an Angular project using the CLI with the "Use Angular Routing" option. Created a feature module and used a scaffolding plug-in in VS Code ("Angular Files" by Alexander Ivanichev) to add a routing class to it. At first I was just adding the component selector directly in the app.component.html and it was working fine, as soon as I added the router-outlet, wired everything together and added the "/submodule" part to the address in the browser, the sub-module component is no longer being displayed in the page and there aren't any errors in the console.
As you can see the scaffolding tool did something a little bit different from the documentation and I tried to modify everything to create a regular NgModule and move things around and it still did not work.
Here's my setup:
app.component.html
<div class="root-container">
<header>
Site name and other things go here
</header>
<aside class="menu">
<h2>Menu</h2>
<nav>
<ul>
<li><a href="*">Menu item 1</a></li>
<li><a href="*">Menu item 2</a></li>
<li><a href="*">Menu item 3</a></li>
<li><a href="*">Menu item 4</a></li>
</ul>
</nav>
</aside>
<div class="content">
<router-outlet></router-outlet>
<!--
<app-my-component></app-my-component>
-->
</div>
<aside>some content</aside>
<footer>This is the footer</footer>
</div>
app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
MyFeatureModule, <- This is the one I'm trying to load
AppRoutingModule
],
providers: [],
exports: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app-routing.module.ts
const routes: Routes = [
{ path: 'submodule', loadChildren: () => import('./featuremodule/feature.module').then(m => m.MyFeatureModule)}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
featuremodule.module.ts
@NgModule({
declarations: [
MyComponent
],
imports: [
CommonModule,
FeatureModuleRoutes
],
providers: [
// some providers
],
exports: []
})
export class MyFeatureModule { }
featuremodule.routing.ts
const routes: Routes = [
{ path: 'mycomponent', component: MyComponent },
];
export const FeatureRoutes = RouterModule.forChild(routes);
Thank you for your help