You can move all route definitions to a separate file.
In a file such as route-definitions.ts:
import { RouteDefinition } from 'angular2/router'; import { HomeComponent } from './home/home.component'; import { AboutComponent } from './about/about.component'; import { InfoComponent } from './info/info.component'; export const RouteDefinitions: RouteDefinition[] = [ { path: '/', name: 'Home', component: HomeComponent, useAsDefault: true }, { path: '/about', name: 'About', component: AboutComponent }, { path: '/info', name: 'Info', component: InfoComponent } ];
Then go back to the app.component.ts file:
import { Component } from 'angular2/core'; import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router'; import { RouteDefinitions } from './route-definitions'; @Component({ selector: 'my-app', templateUrl: 'app/app.component.html', directives: [ROUTER_DIRECTIVES], providers: [ ROUTER_PROVIDERS ] }) @RouteConfig(RouteDefinitions) export class AppComponent { }
Rob louie
source share