Reputation: 5418
I am using Angular 2.0.0-rc.1. I have tried to setup routing with a single route to start with, but nothing is being displayed. No errors are being thrown.
Main.ts
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
import { ROUTER_PROVIDERS } from '@angular/router';
bootstrap(AppComponent, [
ROUTER_PROVIDERS
]);
app.component.ts
import { Component } from '@angular/core';
import { MyComponent} from './my/my.component';
import { HTTP_PROVIDERS } from '@angular/http';
import { ROUTER_DIRECTIVES, Routes } from '@angular/router';
import 'rxjs/Rx';
@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html',
directives: [MyComponent, ROUTER_DIRECTIVES],
providers: [HTTP_PROVIDERS]
})
@Routes([
{ path: '/', component: MyComponent }
])
export class AppComponent { }
app.component.html
<div>
<router-outlet></router-outlet>
</div>
index.html starts with
<html>
<head>
<base href="/">
MyComponent
import { Component } from '@angular/core';
@Component({
selector: 'pr-my',
templateUrl: 'app/my/my.component.html'
})
export class MyComponent {
}
UPDATE: If I add a routerLink into app.component.html and click it, the contents loads as expected. It doesn't load without clicking the link.
<a [routerLink]="['/']">Home</a>
Upvotes: 1
Views: 1052
Reputation: 658037
You need to inject the router
class AppComponent {
constructor(router:Router){}
}
This is a known issue.
Upvotes: 4