在Angular2 RC4中,如何向预编译数组添加组件?

在Angular2 RC4中,如何向预编译数组添加组件?,angular,router,Angular,Router,我刚刚将Angular2项目更新为RC4,当我打开应用程序时,路由器正在控制台中发送此警告消息: router.umd.js:2466 'FrontpageComponent' not found in precompile array. To ensure all components referred to by the RouterConfig are compiled, you must add 'FrontpageComponent' to the 'precompile' arra

我刚刚将Angular2项目更新为RC4,当我打开应用程序时,路由器正在控制台中发送此警告消息:

router.umd.js:2466 'FrontpageComponent' not found in precompile array.  To ensure all components referred to by the RouterConfig are compiled, you must add 'FrontpageComponent' to the 'precompile' array of your application component. This will be required in a future release of the router.

我试图弄清楚我到底需要做什么来解决这个问题,但由于文档很少,我找不到答案。这个预编译数组是什么?我在哪里可以找到它,或者如何添加它?

在较新的路由器版本中,应该不再需要它了


正如我所观察到的,如果我在路由配置中定义了带有“重定向到”的组件,那么该组件也必须在根应用程序中定义为“预编译”。

无需在指令中定义。使用下面的代码

    @Component({
  selector: '...',
  template: '...',
  directives: [],
  precompile: [FrontpageCmponent]
})

您必须将您的组件添加到应用程序组件的meatadata上的a预编译数组中,才能删除该消息

@Component({
selector:'my-app',    
template:`YOUR HTML
    <router-outlet></router-outlet>`
,styleUrls:['app/app.component.css']
,directives:[ROUTER_DIRECTIVES]
,providers:[YOURPROVIDERS]
,precompile:[YOURCOMPONENT]})
export class AppComponent{}
@组件({
选择器:'my-app',
模板:`你的HTML
`
,styleURL:['app/app.component.css']
,指令:[路由器指令]
,提供者:[您的提供者]
,预编译:[YOURCOMPONENT]})
导出类AppComponent{}

如果您将“@angular/router”:“3.0.0-beta.1”升级到“@angular/router”:“3.0.0-beta.2”。那么警告将得到解决。

这似乎是可行的,但为了确保我正确操作,如果这是我的应用程序组件:
从“@angular/core”导入{component};从“@angular/ROUTER”导入{ROUTER_DIRECTIVES}”;从“./components/frontpage/frontpage.component”导入{FrontpageComponent}@组件({moduleId:module.id,选择器:'app',模板:'',指令:[ROUTER_指令],预编译:[FrontpageComponent]})导出类AppComponent{}
我需要导入并添加数组中我路由到的每个组件?即使我读了;-,我也不能声称我完全理解这个主题医生帮我解释了,我现在明白多了。谢谢。我在3.0.0-beta.1中看到了这一点,但升级到3.0.0-beta.2后,我在控制台日志中没有看到任何警告。@NaveedAhmed这里也是。
precompile
ing仍然是包含在组件装饰器中的合适条目吗?
@Component({
selector:'my-app',    
template:`YOUR HTML
    <router-outlet></router-outlet>`
,styleUrls:['app/app.component.css']
,directives:[ROUTER_DIRECTIVES]
,providers:[YOURPROVIDERS]
,precompile:[YOURCOMPONENT]})
export class AppComponent{}