2016-08-15 4 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에로드됩니다.

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 
    } 
] 
}]; 

이가 도움이 Plunker!!

희망을 업데이트!

+0

'children'은 제가 찾고 있던 것이 었습니다 :) 감사합니다. 많이 고맙습니다 만, 여러분이 plunker를 조금 엉망으로 만든 것 같아요. 단지 정보 만 보여줄뿐입니다. 가능하다면 나중에 수정할 수 있도록 게시물에서 업데이트하십시오. [업데이트 된 plunker] (http://plnkr.co/edit/g4UTf82IBtZh6DmVoYLf?p=preview) 또한, 당신은 그 여분의 모든 것들을 필요하지 않습니다 : 신분증 물건. – Baki

+0

답변에 추가 된 업데이트 된 플 런커 덕분에 실제로 대답을 추가 한 플 런커를 업데이트하고 있다는 것을 깨닫지 못했습니다. –

+0

나에게 도움이된다. 고마워. – Kamruzzaman