As a beginner with Angular CLI, I recently executed the following commands at the root of my Angular project.
issue-management\src\webui>ng generate module pages\dashboard
issue-management\src\webui>ng generate component pages\dashboard
To my surprise, the "moduleName-routing.module.ts" files did not generate automatically. I had to create them manually. Even when attempting to create a module with the "--routing" parameter, the result remained the same, and the browser displayed an error message. Here is my folder structure:
https://i.sstatic.net/s1eKO.png
This is my dashboard-routing.module.ts file:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {DashboardComponent} from './dashboard.component';
const routes: Routes = [
{
path: '',
component: DashboardComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class DashboardRoutingModule { }
And here is my dashboard.module.ts file:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DashboardRoutingModule } from './dashboard-routing.module';
import { DashboardComponent } from './dashboard.component';
@NgModule({
declarations: [DashboardComponent],
imports: [
CommonModule,
DashboardRoutingModule
]
})
export class DashboardModule { }
Lastly, this is my app-routing.module.ts file:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: '',
children: [
{path: '', pathMatch: 'full', redirectTo: 'dashboard'},
{path: 'dashboard', loadChildren: './pages/dashboard/dashboard.module#DashboardModule'},
{path: 'issue', loadChildren: './pages/issue/issue.module#IssueModule'},
{path: 'project', loadChildren: './pages/project/project.module#ProjectModule'}
]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
The browser console is displaying the following error message:
ERROR Error: Uncaught (in promise): Error: Cannot find module './pages/dashboard/dashboard.module'
Error: Cannot find module './pages/dashboard/dashboard.module'