2016-08-11 14 views
0

Angularjs 2ルーティングが手動でURLを入力しても、まだ作業していなくても機能しません。Angularjs2ルーティングが機能しない

設定とバージョンは次のとおりです。 -

VAR ngVer = '2.0.0-rc.5 @'; //角度パッケージのバージョンをロックする。 を流してはいけません。

var routerVer = '@ 3.0.0-rc.1'; //ルータのバージョンをロックする var formsVer = '@ 0.3.0'; //フォームのバージョンをロックする var routerDeprecatedVer = '@ 2.0.0-rc.2';

OS: - Ubuntu 14、google chrome。

app.routing.ts

import { Routes, RouterModule } from '@angular/router'; 

    import { HeroesComponent } from './heroes.component'; 


    const appRoutes: Routes = [ 
     { 
     path: 'heroes', 
     component: HeroesComponent, 
     pathMatch: 'full' 
     } 
    ]; 

    export const routing = RouterModule.forRoot(appRoutes); 

app.component.ts

import { Component } from '@angular/core'; 
    import { AppModule } from './app.module'; 
    import { HeroesComponent } from './heroes.component'; 
    import { routing }  from './app.routing'; 



    @Component({ 
     selector : "my-app", 
     template : ` 
         <a routerLink="/heroes1" >Heroes</a> 
         <router-outlet></router-outlet> 
      `, 
     directives: [HeroesComponent] 
    }) 
    export class AppComponent { 
     title = 'Tour of Heroes'; 
    } 

そのホーム・ページになります、URLに何も入力し、初期化されていません"/"

答えて

1

Heroes Compをインポートする理由はありませんルートがそれを処理している場合はonentです。インポートを削除し、app.componentのディレクティブを削除してください。また、公式のAngular.ioサイトでrc.5を使ってアプリケーションを構築するための新しい、適切な方法を参照して戻っていくことも重要です。

クイックスタートをやり直し、新しいmodule.tsファイルを理解してから、ルーティングチュートリアルhereに直接ジャンプして、現在の問題を修正することをお勧めします。

+1

助けてくれてありがとう – aditya

関連する問題