在Angular2路由器的文档中,Configuration部分说
在配置路由器之前,路由器没有路由定义。同时创建路由器并添加路由的首选方法是将@RouteConfig装饰器应用于路由器的主机组件。
但在下面的示例中,它使用的是@Routes
装饰器而不是@RouteConfig
,在许多示例中,我看到了使用@RouteConfig
,这使我感到困惑,因为我不确定这是如何工作的……
@Routes([
{path: '/crisis-center', component: CrisisListComponent},
{path: '/heroes', component: HeroListComponent},
{path: '/hero/:id', component: HeroDetailComponent}
])
注意:我正在尝试使用发布候选版本的angular2
更新
我成功地编写了一个示例,并使用新的装饰器@Routes
使其工作。
Plnkr预览:Angular2 +路由+类型记录+物化-css
Plnker代码:Angular2 +路由+类型记录+物化-css
发布于 2016-05-25 07:00:46
角团队发布了一个全新的路由系统的RC1。在Angular2的beta版本中,路由是使用@RouteConfig
配置的。在RC.1中,这已经更改为@Routes
。您可以通过从@angular/router-deprecated
导入而不是从@angular/router
访问beta路由器。
https://stackoverflow.com/questions/37440693
复制