2016-08-07 7 views
0

보조 경로 내부에 보조 경로가 작동하도록 설정하는 방법을 모릅니다. 내가 좋아하는 루트 구성 요소 및 경로 설정 파일이 있습니다각도 2 새 라우터 rc4 하위 보조 경로가 작동하지 않습니다.

root.routes.ts  
export const rootRoute:RouterConfig=[ 
     ...ChildrenRoute, 
     {path:'',component:ChildrenRootComponent}, 
     {path:'children-root',component:ChildrenRootComponent}, 
     {path:'other',component:OtherComponent'} 
    ]; 

template: 
      '<a routerLink='children-root'>Children root</a> 
      <a routerLink='other'>Other</a> 
      <router-outlet></router-outlet>' 

및 경로와 ChildrenRootComponent이 FirstComponent 및 SecondComponent을 같은 설정 파일 :

children.routes.ts  
    export const ChildrenRoute:RouterConfig=[ 
     {path:"",redirectTo:'/children-root',pathMatch:'full'}, 
     {path:'children-root',component:ChildrenRootComponent, 
       children:[ 
        {path:'',component:FirstComponent}, 
        {path:'first',component:FirstComponent}, 
        {path:'second',component:SecondComponent,outlet:'aux'} 
       ] 
     } 
    ]; 
template: 
     ' <a routerLink='first'>First</a> 
       <router-outlet></router-outlet> 
      <a routerLink='aux:second'>Second</a> 
       <router-outlet name="aux"></router-outlet>' 

지금 어린이 루트에서 경로

-> 두 번째이 괜찮습니다, 그러나 경로 어린이 루트 -> 처음으로가 작동하지 않음 오류 표시 :

Error: Cannot match any routes: 'children-root/second' 

변경 템플릿 :

' <a routerLink='first'>First</a> 
      <router-outlet></router-outlet> 
    <a routerLink='(aux:second)'>Second</a> 
      <router-outlet name="aux"></router-outlet>' 

도 작동하지 않습니다. 오류 :.. 오류 메시지 여기 ')'

Error: Cannot match any routes: 'children-root/second)' 

에주의하고,

localhost:4200/children-root/(aux:second) 

다시로드 브라우저에서 다음과 같이 어떤 '(' 직접 설정 한 URL과 잘 작동 그래서 내가 설정 한 것 같아요 .. routerLink 잘못 검색, 많은, 더

답변

1

RC.4 아직 보조 경로로 routerLink을 지원하지 않습니다 이것에 대해 아무것도 찾을 수없는이 같은 시도 :

+0

A HREF가 SecondComponent에 갈 수에서 작업을 참조해야하지만, 브라우저는 라우터 콘센트에 SecondComponent를로드하지, 전체 페이지를 다시로드합니다. – PengGang

+0

이 href는 페이지를 다시로드하지 않아야합니다. 임대에서 내 애플 리케이션에서 나는 HashLocationStrategy를 사용하고 이것과 비슷한 URL은 페이지를 새로 고침하지 않는다 : '''Second''' –

+0

이것은 여전히 ​​RC.5에서 문제가된다. 이것이 언제 풀릴 지 궁금하다 –

1

Rc4. routerLink는 아직 제대로 지원되지 않습니다. navigateByUrl 또는 수동 'a'태그를 사용하여 원하는 결과를 얻을 수 있습니다. 두 번째로 이동할 때 첫 번째 구성 요소가 표시된다고 가정합니다. 그런 다음

this.router.navigateByUrl('/children-root/(first//aux:second)'); 

또는

<a href="/children-root/(first//aux:second)">Second</a> 

경로의 URL 형성의 설명이 그것은 단지 수정되었습니다 this

+0

어떻게 rc1 및 3.0.0.alpha.x 지원 routerLink 더 나은가요? 누군가 사용 했나요? – PengGang

+1

3.0.0.beta2는 라우터의 최신 버전이며 이전 버전이 더 나은 지원을 제공하지 않습니다. 각 패키지 버전의 나머지 부분은 중요하지 않습니다. –

관련 문제