简体   繁体   中英

What's the difference between @RouteConfig and @Routes

In the documentation of Angular2 Router , Configuration section says

A router has no route definitions until we configure it. The preferred way to simultaneously create a router and add its routes is with a @RouteConfig decorator applied to the router's host component.

but in the example that follows it's using the @Routes decorator instead of @RouteConfig and in many examples i have seen use the @RouteConfig and that confuses me because i'm not sure how this works...

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

Note: I'm trying to use the release candidate version of angular2


Update

I managed to write an example and make it work using the new decorator @Routes .

Plnkr Preview: Angular2 + Routing + Typescript + materialize-css

Plnker Code: Angular2 + Routing + Typescript + materialize-css

The Angular team released RC1 with a totally new routing system. In beta versions of Angular2, routing was configured using @RouteConfig . In RC.1, this has been changed to @Routes . You can access the beta router by importing from @angular/router-deprecated instead of @angular/router

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM