2016-08-15 20 views
0

ルート内でルートを正しく行う方法を理解することに問題があります。私が達成したいこと:私はサイドバーナビゲーションが消えinfo-one/info-twoをクリックしたときに今角2(rc5)ルータ - サイドバーナビゲーション(子ルーティング)

<div class="sidebar-navigation> 
    <a routerLink="/news/info-one" routerLinkActive="active">Info one</a> 
    <a routerLink="/news/info-two" routerLinkActive="active">Info two</a> 
</div> 

<router-outlet></router-outlet> 

App 
    -Contacts (view) 
    -News (view) 
    SidebarNavigation (persistent throught news) 
    -InfoOne (child-view of news) 
    -InfoTwo (child-view of news) 

news.component.html、私が遭遇した問題があります。子供の中に子どものビューを表示するには、角度<router-outlet></router-outlet>を表示するにはどうすればいいですか?<router-outlet></router-outlet>ではありません。

公式チュートリアルのうち、plunkerのフォークを作成しました。 で見てみましょう:app/news.component.tsapp/app.routing.ts


いくつかのより多くのコード:
app.routing.ts

答えて

3

問題がRoutesである

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

import { ContactComponent } from './contact.component'; 
import { NewsComponent, InfoOneComponent, InfoTwoComponent } from './news.component'; 

const appRoutes: Routes = [ 
    { 
    path: '', 
    redirectTo: '/news', 
    pathMatch: 'full' 
    }, 
    { 
    path: 'contact', 
    component: ContactComponent 
    }, 
    { 
    path: 'news', 
    component: NewsComponent 
    }, 
    { 
    path: 'news/info-one', 
    component: InfoOneComponent 
    }, 
    { 
    path: 'news/info-two', 
    component: InfoTwoComponent 
    } 
]; 

export const routing = RouterModule.forRoot(appRoutes); 

おかげで、以下のようにそれを更新、

子ルートとiを定義しました。子配列の中に入る必要があります。子供を追加しないと、ニュースコンポーネント内に追加したものではなく、メインのrouter-outletにロードされます。 Plunker!!

を更新しました

const appRoutes: Routes = [ 
{ 
    path: '', 
    redirectTo: '/news/info-one', 
    pathMatch: 'full' 
}, 
{ 
    path: 'contact', 
    component: ContactComponent 
}, 
{ 
    path: 'news', 
    component: NewsComponent, 
    children : [ 
    { 
    path: '', 
    redirectTo: '/news/info-one', 
    pathMatch: 'full' 
    }, 
    { 
    path: 'info-one', 
    component: InfoOneComponent 
    }, 
    { 
    path: 'info-two', 
    component: InfoTwoComponent 
    } 
] 
}]; 

この情報がお役に立てば幸いです!

+0

「子供たち」は私が探していたものです:)ありがとう、あなたはちょっとしたプランナーを台無しにしてしまったようですが、それは情報のみを表示しています。私はそれを訂正しました。可能であれば、あなたの郵便でそれを将来の参考のために更新してください。 [更新されたplunker](http://plnkr.co/edit/g4UTf82IBtZh6DmVoYLf?p=preview)また、あなたはその余分なものを必要としません:idのもの。 – Baki

+0

答えに追加された更新されたプランカのおかげで、私は実際にいくつかのことを試していました。 –

+0

私にとっては役に立ちます。ありがとう – Kamruzzaman