2017-01-14 4 views
2

내 개인 웹 사이트를 다시 디자인하기 위해 각도 2를 배우려고 시도하지만 내 탐색 표시 줄에서 해당 경로를 클릭 할 때 내 구성 요소가로드되지 않습니다. 내 navbar.html에서 라우터 콘센트가 내 구성 요소를 작동하지 않습니다

난이 링크가 있습니다

 <li><a [routerLink]="['Home']"><i class="fa fa-home"></i></a></li> 
     <li><a [routerLink]="['Langages']">Langages</a></li> 

을하고 난 @RouteConfig 내 app.component.ts 내 경로를 선언

{path: '/', name: 'Home', component: HomeComponent, useAsDefault: true}, 
    {path: '/langages', name: 'Langages', component: LangagesComponent}, 

내 app.component에 .ts 나는 내 탐색 표시 줄을 볼 수있는 템플릿이 있고 아래에 내가 내 HomeComponent를 볼 태그를 추가하고 페이지를 전환하면 HomeCponent가 아니라 내 LangagesComponent를 볼 수 있습니다.이 순간에 HomeComponent 및 다른 구성 요소.

P.S : 내 LangagesComponent에 내가있다 :

import {Component} from "angular2/core"; 

@Component({ 
    templateUrl: "./dev/langages/langages.html" 
}) 

export class LangagesComponent {} 

당신의 도움에 감사드립니다. 경로 구성에서

{path: '', component: HomeComponent, pathMatch: 'full'}, 
{path: 'langages', component: LangagesComponent}, 

path

<li><a [routerLink]="['/']"><i class="fa fa-home"></i></a></li> 
<li><a [routerLink]="['/langages']">Langages</a></li> 
는 선도적 인 /를 포함 할 수 없습니다 루트에서

답변

1

name은 지원되지 않습니다 (즉, 이상 2 년 전에 제거). routerLink 또는 router.navigateByUrl()에서 선두 인 /은 절대 경로를 나타내지 만 /을 제외하면 경로는 상대 경로로 간주됩니다.

은 자세한 내용은 https://angular.io/docs/ts/latest/guide/router.html을 참조하십시오 (대신 TS의 다트를 사용하는 경우를 제외하고는) 더 이상도 더 @RouteConfig 없습니다.

+0

나는이 튜토리얼 2 각도 배우 : https://www.youtube.com/watch?v=fyfY5aqbLNI&list=PL55RiY5tL51olfU2IEqr455EYLkrhmh3n&index=2을 나는 URL 변경이 있고 난에 가면 난 내 구성 요소를로드하지 않도록/langages 또는 내 구성 요소 HomeComponent in "/" – ryfl

+0

2016 년 1 월에 게시되었습니다.이 내용은 beta.1에 관한 내용입니다. https://github.com/angular/angular/blob/master/CHANGELOG.md#200-beta1-catamorphic- involution-2016-01-08 이후 변경된 사항을 직접 확인하십시오. –

1

nameuseAsDefault(not sure)은 오래 전에 삭제되었습니다. 지금 당신이 다음과 같이 설정하여 경로를해야는

{ path: '', redirectTo: 'home', pathMatch: 'full'}, 
{ path: "home", component: HomeComponent},  
{ path: 'language', component: LangagesComponent }, 

.HTML

<li><a routerLink="home"><i class="fa fa-home"></i></a></li> 
<li><a routerLink="language">Langages</a></li> 

참고 : 는 또한 라우터 콘센트 어딘가에 배치 HTML에 라우터를 사용하여 동적 뷰를로드 할 수 있는지 확인하십시오.

관련 문제