繁体   English   中英

角2 es5分量路线

[英]angular 2 es5 component route

我正在尝试使用ES5实现Angular 2路由。

以下是appComponent

(function(app) {
  app.AppComponent =function() {};
  app.AppComponent = ng.core
    .Component({
      selector: 'my-app'
    }).
    View({
        templateUrl: 'app.html',
        directives: [ng.router.ROUTER_DIRECTIVES]
    })
    .Class({
      constructor: function() {
          this.name = "pankaj Badukale";
      }
    });

    **ng.router.RouteConfig([
        {
            path: "login",
            component: app.LoginComponent,
            as: "login"
        }
    ]);**

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

app.html

<h1>
    {{name}}  
    <a [routerLink]="['/login']">Home</a>
    <router-outlet></router-outlet>
</h1>

我想知道如何在组件上配置路由。

我搜索了很多,但人们刚刚定义了视图,组件,类。

有人有想法吗?

Component和RouteConfig都是装饰器,你可以用角度2(beta)编写装饰器

app.AppComponent = ng.core.Component(...)(app.AppComponent);
app.AppComponent = ng.router.RouteConfig(...)(app.AppComponent);


这是你的工作副本......

(function(app) {
  app.AppComponent =function() {};
  app.AppComponent = ng.core
    .Component({
      selector: 'my-app'
    }).
    View({
        templateUrl: 'app.html',
        directives: [ng.router.ROUTER_DIRECTIVES]
    })
    .Class({
      constructor: function() {
          this.name = "pankaj Badukale";
      }
    });

    app.AppComponent = ng.router.RouteConfig([
        {
            path: "login",
            component: app.LoginComponent,
            as: "login"
        }
    ])(app.AppComponent);

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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