2017-02-12 13 views
0

scotch.ioのng2バージョンを作成中ですangular-ui-router tutorial。 私はhomeaboutページの基本的なナビゲーションを達成することができます。 子供のためのナビゲーション、つまりlistparagraphを作成することができます。私はaboutのページで立ち往生しています。私は約ページに移動することができますが、componentaboutを対応するアウトレットにレンダリングできません。これは私がやっているものです:Angular2:子コンポーネントの複数のルータコンセント

について-routing.module.ts

export const aboutRoutes: Routes = [ 
    { 
     path: 'about', 
     component: AboutComponent, 
     children: [ 
      { 
       path: 'about', 
       outlet: 'aboutOne', 
       component: AboutOneComponent 
      }, 
      { 
       path: 'about', 
       outlet: 'aboutTwo', 
       component: AboutTwoComponent 
      } 
     ] 
    } 
]; 

<div class="jumbotron text-center"> 
    <h1>The About Page</h1> 
    <p>This page demonstrates <span class="text-danger">multiple</span> and <span class="text-danger">named</span> views.</p> 
</div> 
<div class="row"> 
    <div class="col-sm-6"> 
     <router-outlet name="aboutOne"></router-outlet> 
     <router-outlet name="aboutTwo"></router-outlet> 
    </div> 
</div> 

about.routes.ts about.component.html

import { NgModule } from '@angular/core'; 
import { RouterModule } from '@angular/router'; 

import { aboutRoutes } from './about.routes'; 
@NgModule({ 
    imports: [RouterModule.forChild(aboutRoutes)], 
    exports: [RouterModule] 
}) 
export class AboutRoutingModule { 

} 

私は何が欠けているのか分かりません。 aboutページはレンダリングされていますが、子コンポーネントをレンダリングしていないため、コンソールにエラーはありません。ここには完全なgithub repoがあります。

答えて

1

<router-outlet>という名前で遊んだ後、私はそれを理解しました。私は適切な道を与えていませんでした。ユーザーがaboutページに入ると、両方のコンポーネントが対応するアウトレットにレンダリングされるはずです。両方に相対URL /パスはありません。デフォルトの子はaboutです。そこでpath:'about'path:''に更新しました。そしてそれは働き始めた。これが誰かに役立つことを願っています。 path問題を強調してくれてありがとう@Pradeep

about.routes.ts

export const aboutRoutes: Routes = [ 
    { 
     path: 'about', 
     component: AboutComponent, 
     children: [ 
      { 
       path: '', 
       outlet: 'aboutOne', 
       component: AboutOneComponent, 
       pathMatch: 'full' 
      }, 
      { 
       path: '', 
       outlet: 'aboutTwo', 
       component: AboutTwoComponent, 
       pathMatch: 'full' 
      } 
     ] 
    } 
]; 

3

誤差はおよそコンポーネントのルーティングであるあなたはコンポーネントだけでなく、親1の両方のために、パスの同じ名前を使用していたねえ@hiteshおそらく、これを変更し、この

export const aboutRoutes: Routes = [ 
    { 
     path: 'about', 
     component: AboutComponent, 
     children: [ 
      { 
       path: 'aboutOne', 
       outlet: 'aboutOne', 
       component: AboutOneComponent 
      }, 
      { 
       path: 'aboutTwo', 
       outlet: 'aboutTwo', 
       component: AboutTwoComponent 
      } 
     ] 
    } 
]; 

のようにそれを試してみてください可能性がありますすべてのケースでaboutというURLが見つかった場合には、URLを基にしてコンポーネントをロードしようとします。この場合、子コンポーネントはレンダリングできません。

+0

ありがとうございました。物事は、 'aboutOne'と' aboutTwo'の両方がルートではありませんが、あなたはscotch.ioチュートリアルを見ることができるので、ビューです。 http://embed.plnkr.co/IzimSVsstarlFviAm7S7/previewこれには2つの 'ui-view'があり、ルートテンプレートはこれらのビューに収まっています。私はルータ出口を使って同様のことをしたい。私のコンポーネントが同じルートの対応するアウトレットに入ることを確認してください –

+0

あなたはいくつかのプランナーであなたの問題を再現してくださいますか? –

+0

私はレポコードを持っています。 https://github.com/hk-skit/angular2routingあなたはそれを調べることができます。私はangular-cliを使ってレポを作成しました。したがって、それをplunkrに移動することは時間がかかるでしょう。 –

関連する問題