延迟加载模块不能与RouterModule.forRoot一起使用

时间:2017-04-11 10:32:17

标签: angular

我使用Angular2版本2.4.0
项目用angular-cli创建 我有像这样的路由器懒惰的dymanic

const tenantRoutes: Routes = [
    {
        path: '',
        redirectTo: '/Login',
        pathMatch: 'full'
    },
    {
        path: 't', loadChildren: () => new Promise(resolve => {
            (require as any).ensure([], function (require: any) {
                let tenant: string = '';
                if (localStorage.getItem('localStorage') != null) {
                    tenant = JSON.parse(localStorage.getItem('localStorage')).tenantName;
                    resolve(require('./tenant/' + tenant.toUpperCase() + '/module')[tenant.toUpperCase() + 'Module']);
                } else {
                    resolve(require("./share/shareComponent/redirect")["RedirectModule"]);
                }
            })
        })
    },
    { path: 'Error404', component: Error404 }
];

@NgModule({
  imports: [
    RouterModule.forRoot(
      tenantRoutes
    )
  ],
  exports: [
    RouterModule
  ],
  providers: [
    CanDeactivateGuard
  ]
})
export class AppRoutingModule { }

当我运行ng-serve时,它有问题

ERROR in Error encountered resolving symbol values statically. Reference to a local (non-exported) symbol 'tenantRoutes'. Consider exporting the symbol (position 16:7 in the original .ts file), resolving symbol AppRoutingModule

我如何修复这个错误?感谢

0 个答案:

没有答案