【发布时间】:2018-12-11 16:01:56
【问题描述】:
我想在我的项目中为管理员添加延迟加载的路由。我正在使用 ASP Net Core 后端和 Angular 6 前端,所以我的编译代码输出目录是:wwwRoot/Angular/dist。当我编译项目时,我看到那里存在文件“admin-admin-module-ngfactory.js,但是当我尝试进入页面'/admin/dash'时,它会抛出错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
Error: Uncaught (in promise): Error: Loading chunk admin-admin-module-ngfactory failed.
(error: http://localhost:5000/admin-admin-module-ngfactory.js)
Error: Loading chunk admin-admin-module-ngfactory failed.
(error: http://localhost:5000/admin-admin-module-ngfactory.js)
这是我的路由模块:
admin-routing.module.ts:
const routes: Routes = [
{ path: 'dash', component: AdminDashboardComponent, pathMatch: 'full'}
];
@NgModule({
imports: [
RouterModule.forChild(routes)
],
exports: [RouterModule],
declarations: []
})
export class AdminRoutingModule { }
和app-routing.module.ts:
const routes: Routes = [
{ path: 'dashboard', component: DashboardComponent },
{ path: 'error', component: ErrorComponent },
{ path: 'admin', loadChildren: './admin/admin.module#AdminModule' },
{ path: '', pathMatch: 'full', redirectTo: 'dashboard' },
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [RouterModule]
})
export class AppRoutingModule { }
更新:
如果我使用 dotnet run(使用 ng build --aot)运行项目,它不起作用,但如果我只使用 ng serve --aot 启动 Angular 应用程序,它会起作用。
【问题讨论】:
-
仔细检查路径
-
我已经检查了路径,我确定这是正确的。