For example, I use router-link like this:
<li><a [router-link]="['/start']">Start</a></li>
But how can I change the router to /start by typescript?
For example, I use router-link like this:
<li><a [router-link]="['/start']">Start</a></li>
But how can I change the router to /start by typescript?
I believe you're asking how to configure your routes in Angular 2.
2) Use @RouteConfig to setup your routes on a component
Optional: Add a hashbang (#) to your url
Here's 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
]);
ROUTER_PROVIDERS should go before LocationStrategy. Otherwise it wont work. (spent an hour figuring this out)