Angular 4.1.3 路由无法从父模块解析子模块
Angular 4.1.3 routing could not resolve child module from parent module
提前感谢您的帮助!!!!
您好,如题所示。我收到以下错误...。我正在尝试进行大量研究并弄清楚,但我所做的似乎无济于事。这里有一些重要的文件,有没有人有过这个问题的经验或看到问题? (同样错误来自 ng serve 和 ng build 但是 ng serve 它首先失败然后自动重建并完美运行。所以它确实适用于 ng serve 但因为第一个是失败我无法构建它(这显然是主要问题)
ERROR in Could not resolve "patient.module" from "d:/Downloads/AngularApp/AngularApp/src/app/app.module.ts".
app.routing.ts
const patientRoutes: Routes = [
{
path: 'patient',
loadChildren: 'app/patient/patient.module.ts#PatientModule',
}
];
const nurseRoutes: Routes = [
{
path: 'nurse',
loadChildren: 'app/nurse/nurse.module.ts#NurseModule',
}
];
const appRoutes: Routes = [
{
path: '',
redirectTo: 'auth',
pathMatch: 'full'
},
{
path: 'auth',
component: AutenticationComponent
},
...patientRoutes,
...nurseRoutes
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, {useHash: true});
patient.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { patientRouting } from './patient.routing';
import { PatientDashboardComponent } from './dashboard/patient-dashboard.component';
@NgModule({
imports: [
CommonModule,
patientRouting
],
declarations: [
PatientDashboardComponent
]
})
export class PatientModule { }
patient.routing.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { PatientComponent } from './patient.component';
import { PatientDashboardComponent } from './dashboard/patient-dashboard.component';
import { PatientVideoComponent } from './video/video-chat.component';
const patientRoutes: Routes = [
{
path: 'patient',
component: PatientComponent,
children: [
{
path: '',
component: PatientVideoComponent,
children: [
{
path: '',
component: PatientDashboardComponent,
}
]
}
]
}
];
export const patientRouting: ModuleWithProviders = RouterModule.forChild(patientRoutes);
angularcli.json
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": ["assets"],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
我终于在这方面找到了一些东西,这似乎有效。他们改变了他们的路由结构,所以不用说 app/patient 而是直接使用 ./patient 例如。
app/dir1/dir2/...
(假设routes模块是在app目录下配置的)到
./dir1/dir2/...
可以解决这个问题:
const routes: Routes = [
{
path:'customers',
loadChildren: './customers/customers.module#CustomersModule'
},
{
path: 'orders',
loadChildren: './orders/orders.module#OrdersModule'
},
{
path:'contacts',
loadChildren:'./contacts/contacts.module#ContactsModule'
},
{
path:'',
redirectTo:'',
pathMatch:'full'
}
];
提前感谢您的帮助!!!!
您好,如题所示。我收到以下错误...。我正在尝试进行大量研究并弄清楚,但我所做的似乎无济于事。这里有一些重要的文件,有没有人有过这个问题的经验或看到问题? (同样错误来自 ng serve 和 ng build 但是 ng serve 它首先失败然后自动重建并完美运行。所以它确实适用于 ng serve 但因为第一个是失败我无法构建它(这显然是主要问题)
ERROR in Could not resolve "patient.module" from "d:/Downloads/AngularApp/AngularApp/src/app/app.module.ts".
app.routing.ts
const patientRoutes: Routes = [
{
path: 'patient',
loadChildren: 'app/patient/patient.module.ts#PatientModule',
}
];
const nurseRoutes: Routes = [
{
path: 'nurse',
loadChildren: 'app/nurse/nurse.module.ts#NurseModule',
}
];
const appRoutes: Routes = [
{
path: '',
redirectTo: 'auth',
pathMatch: 'full'
},
{
path: 'auth',
component: AutenticationComponent
},
...patientRoutes,
...nurseRoutes
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, {useHash: true});
patient.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { patientRouting } from './patient.routing';
import { PatientDashboardComponent } from './dashboard/patient-dashboard.component';
@NgModule({
imports: [
CommonModule,
patientRouting
],
declarations: [
PatientDashboardComponent
]
})
export class PatientModule { }
patient.routing.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { PatientComponent } from './patient.component';
import { PatientDashboardComponent } from './dashboard/patient-dashboard.component';
import { PatientVideoComponent } from './video/video-chat.component';
const patientRoutes: Routes = [
{
path: 'patient',
component: PatientComponent,
children: [
{
path: '',
component: PatientVideoComponent,
children: [
{
path: '',
component: PatientDashboardComponent,
}
]
}
]
}
];
export const patientRouting: ModuleWithProviders = RouterModule.forChild(patientRoutes);
angularcli.json
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": ["assets"],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
我终于在这方面找到了一些东西,这似乎有效。他们改变了他们的路由结构,所以不用说 app/patient 而是直接使用 ./patient 例如。
app/dir1/dir2/...
(假设routes模块是在app目录下配置的)到 ./dir1/dir2/...
可以解决这个问题:
const routes: Routes = [
{
path:'customers',
loadChildren: './customers/customers.module#CustomersModule'
},
{
path: 'orders',
loadChildren: './orders/orders.module#OrdersModule'
},
{
path:'contacts',
loadChildren:'./contacts/contacts.module#ContactsModule'
},
{
path:'',
redirectTo:'',
pathMatch:'full'
}
];