Angular 2 ES5 cheat sheet说要这样做:
var MyComponent = ng.router.RouteConfig([
{ path: '/:myParam', component: MyComponent, as: 'MyCmp' },
{ path: '/staticPath', component: ..., as: ...},
{ path: '/*wildCardParam', component: ..., as: ...}
]).Class({
constructor: function() {}
});
但是,我无法弄清楚如何在该类上指定@Component
内容,以便我可以实际实例化它。例如,
ng.router.RouteConfig([...]).Component({})
引发异常,因为.RouteConfig
的结果没有.Component
方法。同样,.Component
的结果也没有.RouteConfig
方法。你是如何设置的?
答案 0 :(得分:1)
这是我设法最终开始工作的一种可能方式。我愿意向其他人发布更好的解决方案:
app.AppComponent = ng.core
.Class({
constructor: [
function() {
}
]
});
app.AppComponent.annotations = [
ng.router.RouteConfig([
{ path: '/', component:app.ListsComponent, name:'Lists' },
{ path: '/children', component:app.ChildrenComponent, name:'Children' }
]).annotations[0],
new ng.core.ComponentMetadata({
selector: 'the-app',
template: '<h1>App!!!</h1>' +
'<a [routerLink]="[\'Children\']">Children</a>' +
'<a [routerLink]="[\'Lists\']">Lists</a>' +
'<router-outlet></router-outlet>',
directives:[
app.ListsComponent,
app.ChildrenComponent,
ng.router.ROUTER_DIRECTIVES
]
})
];