How to change router to typescript in angular2?
I suppose you are asking how to set up routes in Angular 2.
- 1) import and load your router
2) Use @RouteConfig to configure routes on the component
Optional: add hashbang (#) to your URL
Here is an example:
import {Component, View, bind, bootstrap} from 'angular2/angular2';
import {routerInjectables, routerDirectives, Router, RouteConfig} from 'angular2/router';
import {LocationStrategy, Location, HashLocationStrategy } from 'angular2/router'; // options2: HTML5LocationStategy
// Components
import {Home} from 'home';
import {SomewhereElse} from 'somePlace';
@Component({
selector: 'app-name'
})
@View({
template: '<router-outlet></router-outlet>',
directives: [routerDirectives]
})
@RouteConfig([
{path: '/start', as: component: Home},
{path: '/place/:placeId', component: SomewhereElse}
])
class AppName {}
bootstrap(AppName, [
routerInjectables,
bind(LocationStrategy).toClass(HashLocationStrategy) // for hashbang routes (/#/)
// alternative: use HTML5LocationStrategy
]);