2016-06-26 16 views
0

私はrc3でルーティングを取得するための指示に従ったと思います。これはrc1でうまくいきます。私はapp.routes、app.providersを作成し、それは次のようになります。角度2 rc3ルーティングの問題

main.ts:

import {bootstrap} from '@angular/platform-browser-dynamic'; 
 
import {APP_ROUTER_PROVIDER} from './app.routes'; 
 
import {HTTP_PROVIDERS} from '@angular/http'; 
 
import {AppComponent} from './app.component'; 
 

 
bootstrap(AppComponent, [APP_ROUTER_PROVIDER, HTTP_PROVIDERS]);

app.component.ts:

import {Component, OnInit} from '@angular/core'; 
 
import {ROUTER_DIRECTIVES, Router} from '@angular/router'; 
 
import { APP_PROVIDERS } from './app.providers'; 
 

 

 
@Component({ 
 
    selector: 'my-app', 
 
    template: '<router-outlet></router-outlet>', 
 
    directives: [ROUTER_DIRECTIVES], 
 
    providers: [APP_PROVIDERS] 
 
}) 
 
export class AppComponent implements OnInit { 
 
    constructor(private router: Router) { 
 

 

 
    } 
 
    ngOnInit() { 
 
     this.router.navigate(['home']); 
 
    } 
 
}

app.providers.ts

import { bind } from '@angular/core'; 
 
import { HTTP_PROVIDERS } from '@angular/http'; 
 
import { FORM_PROVIDERS, LocationStrategy, HashLocationStrategy } from '@angular/common'; 
 
    
 
export const APP_PROVIDERS = [ 
 
    
 
    FORM_PROVIDERS, 
 
    HTTP_PROVIDERS 
 
];

home.routes.ts

import {RouterConfig} from '@angular/router'; 
 
import {HomeComponent} from './home.component'; 
 

 
export const HomeRoutes: RouterConfig = [ 
 
    { path: 'home', component: HomeComponent, terminal: true } 
 
];

home.component.ts

import {Component} from '@angular/core'; 
 
import {ROUTER_DIRECTIVES, Router} from '@angular/router'; 
 

 
@Component({ 
 
    selector: 'kg-home', 
 
    templateUrl: './home.component.html', 
 
    directives: [ROUTER_DIRECTIVES] 
 
}) 
 

 
export class HomeComponent { 
 
    constructor(private router: Router) { 
 
     console.log('in home component') 
 
    } 
 
}

が、私はそれを実行したときに、私が取得: enter image description here

すべてのヘルプは、私は2日間、今このようなものを見つめてきた、高く評価されるだろう。

答えて

1

あなたはここで、端末が何であるかをデフォルトルート

export const HomeRoutes: RouterConfig = [ 
    { path: '', redirectTo: '/home', terminal: true}, 
    { path: 'home', component: HomeComponent } 
]; 
+0

が必要ですか? –

+0

私はそれについてまだよく分かりません。私はルータに、これがマッチすれば他の一致するルートを確認する必要はないと伝えます。 –

+0

ohh大丈夫です:) –