如何在Angular2编译器/cli ngc命令中使用RouterModule.forRoot() [英] How to use RouterModule.forRoot() in Angular2 compiler/cli ngc command

查看:139
本文介绍了如何在Angular2编译器/cli ngc命令中使用RouterModule.forRoot()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下appRoutingModule:

Let's say i have the following appRoutingModule:

export const routes: Route[] = [
  {
    path: '',
    component: ApplicationlistComponent
  }
];

@NgModule( {
  imports: [ ApplicationsModule, RouterModule.forRoot( routes ) ],
  exports: [ RouterModule ],
  declarations: [ApplicationlistComponent]
} )
export class AppRoutingModule {
}

使用 ngc cli命令进行编译时,将出现以下错误:

When compiling this with the ngc cli command it will give the following error:

Error: Error encountered resolving symbol values statically. Calling function 'RouterModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppRoutingModule in C:/git/mxt-frontend/landing-page-client/src/client/app/app-routing.module.ts, resolving symbol AppRoutingModule in C:/git/mxt-frontend/landing-page-client/src/client/app/app-routing.module.ts

我尝试将其放在导出的const中:

I tried putting it inside an exported const:

export const routerModule =  RouterModule.forRoot( routes );

但这会产生此错误:

Error: Error encountered resolving symbol values statically

要使其正常工作,有什么解决方法/修补程序?如果无法将其传递给RouterModule,该如何定义路由?

What is the workaround/fix to get this working? How do i define my routes if i can't pass it to the RouterModule?

我正在使用版本:

"@angular/compiler": "~2.4.0",
"@angular/compiler-cli": "~2.4.0",
"@angular/platform-server": "~2.4.0",
"@angular/router": "~3.4.0"

推荐答案

我通过将angular恢复到2.3.1版来解决了这个问题. 似乎在2.4.0版本中已损坏..

I resolved this by reverting angular back to version 2.3.1. Looks like it's broken in the 2.4.0 release..

这篇关于如何在Angular2编译器/cli ngc命令中使用RouterModule.forRoot()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆