【问题标题】:What's the difference between @RouteConfig and @Routes@RouteConfig 和 @Routes 有什么区别
【发布时间】:2016-05-25 14:49:59
【问题描述】:

Angular2 Router 的文档中,配置部分说

在我们配置它之前,路由器没有路由定义。同时创建路由器并添加其路由的首选方法是将 @RouteConfig 装饰器应用于路由器的主机组件。

但在下面的示例中,它使用@Routes 装饰器而不是@RouteConfig,在许多示例中我看到使用@RouteConfig,这让我感到困惑,因为我不确定它是如何工作的......

@Routes([
    {path: '/crisis-center', component: CrisisListComponent},
    {path: '/heroes',        component: HeroListComponent},
    {path: '/hero/:id',      component: HeroDetailComponent}
])

注意:我正在尝试使用 angular2 的候选发布版本


更新

我设法编写了一个示例,并使用新的装饰器@Routes 使其工作。

Plnkr 预览:Angular2 + Routing + Typescript + materialize-css

Plnker 代码:Angular2 + Routing + Typescript + materialize-css

【问题讨论】:

    标签: angular configuration routes router


    【解决方案1】:

    Angular 团队发布了带有全新路由系统的 RC1。在 Angular2 的 beta 版本中,路由是使用 @RouteConfig 配置的。在 RC.1 中,这已更改为 @Routes。您可以通过从 @angular/router-deprecated 而不是 @angular/router 导入来访问 beta 路由器

    【讨论】:

    • 你有什么例子吗?谢谢
    • angular.io/docs/ts/latest/tutorial/toh-pt5.html 的路由教程中有一个使用@angular/router-deprecated 的示例。根据您的项目,切换到router-deprecated 可能无法解决某些导入问题。如果是这样,请在 node_modules 中的 @angular 文件夹中搜索丢失的类。从 beta 版迁移到 RC.1 是一个反复试验的过程。
    猜你喜欢
    • 1970-01-01
    • 2010-10-02
    • 2011-12-12
    • 2010-09-16
    • 2012-03-14
    • 2012-02-06
    • 2011-02-25
    • 2011-11-22
    • 2015-03-26
    相关资源
    最近更新 更多