Another example inspired by the Angular2 tutorial Traveling Heroes (you can find the full tutorial in simple javascript here: https://programming.sereale.fr/2016/03/22/rails-and-angular2-react-the-tour -of-heroes / ):
var MyApp = ng.core.Component({
selector: 'my-app',
directives: [ng.router.ROUTER_DIRECTIVES],
providers: [ng.router.ROUTER_PROVIDERS, ng.http.HTTP_PROVIDERS, HeroService],
template: "<h1>{{title}}</h1> \
<nav> \
<a [routerLink]=\"['Heroes']\">Heroes</a> \
<a [routerLink]=\"['Dashboard']\">Dashboard</a> \
</nav> \
<router-outlet></router-outlet>"
}).Class({
constructor: [ ng.router.Router, function(router) {
router.config([
{ path: '/dashboard', name: 'Dashboard', component: DashboardComponent, useAsDefault: true },
{ path: '/heroes-list', name: 'Heroes', component: HeroesComponent },
{ path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent }
]);
this.title = 'Tour of Heroes';
}]
});
source
share