I think this is better:
In main.ts:
import { ROUTER_PROVIDERS } from 'angular2/router'; bootstrap(AppComponent, [ ROUTER_PROVIDERS, provide(LocationStrategy, { useClass: HashLocationStrategy }) ]);
In your component.ts file:
import { Router, RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router'; import { APP_ROUTES } from './route.config'; @RouteConfig(APP_ROUTES)
And create a route.config.ts file:
import { Route } from 'angular2/router'; import { HomeComponent } from './home/home.component'; import { TableComponent } from './table/table.component'; export var Routes = { home: new Route({ path: '/home', component: HomeComponent, name: 'Home', useAsDefault: true, data: { title: 'Home' } }), table: new Route({ path: '/table/:table', component: TableComponent, name: 'Table' }) }; export const APP_ROUTES = Object.keys(Routes).map(r => Routes[r]);
source share