如何在 Angular2 中使用纯 JavaScript 的 RouteConfig?

How to use RouteConfig in Angular2 with plain JavaScript?

我正在使用 Angular 2 和纯 JavaScript 构建一个应用程序,我找不到任何关于如何将 RouteConfig 用于 JavaScript(不是 ts)的示例。

任何人都可以给我一个如何使用的例子。 我这样试过,但没有用:

(function(app) {
    app.MainComponent =
        ng.core.Component({
                selector: 'app',
                templateUrl: 'app/components/main/main.view.html'
            })
            .Class({
                constructor: function() {}
            })
            .RouteConfig([
                {path: '/', redirectTo: '/job'},
                {path: '/job', component: JobViewComponent }
            ])
    ;

})(window.app || (window.app = {}));

我还有其他文件 JobView

(function(app) {
    app.JobViewComponent =
        ng.core.Component({
                selector: 'job-view',
                templateUrl: 'app/components/job_view/job_view.view.html'
            })
            .Class({
                constructor: function() {}
            });
})(window.app || (window.app = {}));

谢谢。

RouteConfig 是一个装饰器,所以你应该这样使用它:

app.MainComponent =
  ng.core.Component({
    selector: 'app',
    templateUrl: 'app/components/main/main.view.html'
  })
  .Class({
    constructor: function() {}
  });

app.MainComponent = ng.core.RouteConfig([
  {path: '/', redirectTo: '/job'},
  {path: '/job', component: JobViewComponent }
])(app.MainComponent);

这是一个有效的插件:https://plnkr.co/edit/ZcSGHSsV8fBOc4TnI68h?p=preview