2017-09-02 122 views
1

遇到錯誤遇到靜態解析符號值。引用本地(非導出)符號'protectedRoutes'。考慮導出符號(在原始.ts文件中的位置9:7),解析/protected/protected.routes.ts中的符號ProtectedRouteModuleAngular 4急切加載lambda funciton

請告知如何解決此問題?

const protectedRoutes: Routes = [ 
     { 
     path: 'protected', 
     component: LayoutComponent, 
     canActivate: [AuthGuard], 
     children:[ 
      { path:'', redirectTo: 'contact', pathMatch:'full'}, 
      { path:'support', loadChildren:() => SupportModule}, 
      { path:'contact', loadChildren:() => ContactModule}, 
      // { path:'support', loadChildren:'./support/support.module#SupportModule'}, 
      // { path:'contact', loadChildren:'./support/contact.module#ContactModule'}, 
     ] 
     } 
    ]; 

    @NgModule({ 
     imports: [RouterModule.forRoot(protectedRoutes)], 
     exports: [RouterModule] 
    }) 
    export class ProtectedRouteModule { } 

回答

1

您必須導出函數,如錯誤消息所述。

export function loadSupportModule() { 
    return SupportModule 
} 

然後使用它。

{ path:'support', loadChildren: loadSupportModule }