我刚刚将我的项目更新为 Angular-CLI,我在:
"@angular/cli": "1.0.0",
"@angular/compiler-cli": "4.0.1",
我收到一个错误,说:
考虑将函数或 lambda 替换为对 导出函数角度 CLI
从这个.ts
文件:
/userManagement.routeting.ts
import {RouterModule, Routes} from "@angular/router";
export const routes: Routes = [
{
path: '', redirectTo: 'unlockUserID', pathMatch: 'full'
},
{
path: 'unlockUserID',
loadChildren: ()=> System.import('./unlockUserID/unlockUserID.module')
.then((imports: any)=> imports.UnlockUserIdModule)
},
{
path: 'changePassword',
loadChildren: ()=> System.import('./changePassword/changePassword.module')
.then((imports: any)=> imports.ChangePasswordModule)
},
{
path: 'maintainOfficeHierarchy',
loadChildren: ()=> System.import('./maintainOfficeHierarchy/maintainOfficeHierarchy.module')
.then((imports: any)=> imports.MaintainOfficeHierarchyModule)
},
];
export const routing = RouterModule.forChild(routes);
比在我的模块中:
@NgModule({
imports: [
SmartadminModule,
routing,
],
providers: [],
})
export class UserManagementModule {
}
--------------------------------更新1-----------------------------
不得不将其更改为:
export const routes: Routes = [
{
path: '', redirectTo: 'unlockUserID', pathMatch: 'full'
},
{
path: 'unlockUserID',
loadChildren: './unlockUserID/unlockUserID.module',
data: {pageTitle: 'unlockUserID'}
},
{
path: 'changePassword',
loadChildren: './changePassword/changePassword.module',
data: {pageTitle: 'changePassword'}
},
export const routing: ModuleWithProviders = RouterModule.forRoot(routes, {useHash: true});
现在我收到以下错误:
Error: RouterModule.forRoot() called twice. Lazy loaded modules should use RouterModule.forChild() instead.
---------------------------更新2---------------------------
我把它改成了
export const routing: ModuleWithProviders = RouterModule.forChild(routes)
;
现在我收到一个错误说:
Cannot find 'default' in './changePassword/changePassword.module'
如果我单击更改密码选项卡,其他链接也是如此。
根据 https://github.com/rangle/angular-2-aot-sandbox#arrow-function-exports-top
箭头函数在传递给 AoT 时不起作用
NgModule
。
因此,您不应该在Routes
中定义箭头函数。
对于通过路由器延迟加载的模块,不推荐通过字符串导入。
NG 更新将自动处理此问题。新语法利用了生态系统范围内对导入的支持,而不是我们的自定义重写。
您的 load子路由配置应从字符串更改,例如
loadChildren: './admin/admin.module#AdminModule'
到导入语句,例如
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule)