2016-06-05 7 views
0

왜이 서브 루팅이 작동하지 않습니까? 나는이 질문을 확인했다 A similar issue. 보다 구체적인 경로를 먼저 이동함으로써 주어진 해결책을 구현했지만 문제가 해결되지 않았습니다. 내가 Whatsup에있는 링크를 클릭하면왜 내 서브 루트가 angular2에서 작동하지 않습니까?

App.component.ts는

import {Whatsup} from "./whatsup.component"; 
    ... 
    template:` 

    <li id="whatsup" (click)="loadField('whatsup')" ><a [routerLink]="['/whatsup/...']"> Whatsup?</a></li> 
    <router-outlet></router-outlet> 
    ` 
    ... 

    @Routes([ 
     {path: '/whatsup/...', component: Whatsup} 
    ]) 

Whatsup.component.ts는

import {Calendar} from "./Calendar.component"; 

     ... 

     template:` 
     <li class="list-group-item"><a [routerLink]="['/today']">{{today | date:'EEEEE'}}</a></li> 
     <router-outlet></router-outlet> 
     ` 
     ... 

@Routes([ 
    {path:"/today", component: Calendar} 
]) 

Whatsup 성공적으로로드,하지만 난이 오류가 발생합니다 :

미처리 Promise 거부 : 경로를 찾을 수 없습니다. 현재 세그먼트 : '오늘' 사용 가능한 경로 : [ '/ whatsup/...', '/ our-recommendations', '/ leave-review', '/ deals-in-town']. ; 구역 : 각; 작업 : Promise.then; 값 : Object {message : "모든 경로와 일치 할 수 없습니다. 현재 ...", 스택 : "BaseException @http://localhost:3000 ..."}

답변

0

/...은 더 이상 RC.x 라우터에서 필요하지 않으며 인식되지 않습니다. 그냥 제거 :

{path: '/whatsup', component: Whatsup} 

RC.x 라우터에는 몇 가지 문제가 있으며 현재 Angular 팀의 진행 방법이 명확하지 않습니다. router-deprecated에서 이전을 시작하는 경우 라우터 스토리가 앞으로 어떻게 진행될 것인지 명확해질 때까지 사용되지 않는 라우터를 유지하는 것이 좋습니다. @angular/router

  • 일부 알려진 문제는 당신이 당신의 AppComponent에 라우터 (constructor(router:Router) {})를 주입하거나 보장 또는 AppComponent의 템플릿 그렇지 않으면 라우터가 전혀 호출되지 않습니다 routerLink을 포함 .

  • @Routes() 내 경로를 지정하면 더 구체적인 경로가 먼저 나오고 구체적인 경로가 덜 오게됩니다. 그렇지 않으면 첫 번째 경로 이후의 경로는 찾을 수 없습니다.

+0

'...'자리를 비 웠음에도 문제가 해결되지 않았으므로 지금은 사용 중지 된 라우터로 되돌아갑니다. – Dan

+0

'[routerLink] = "[ '/ whatsup/...']'에'/ ... '표시가있는 것을 보았습니다. 이것은 @ angle/router-deprecated에서도 아닙니다. 또한 http://stackoverflow.com/questions/37605119/angular2-router-angular-router-how-to-set-default-route/37605802#37605802하지만 '@ angular/router-deprecated'로 머무르는 것이 좋습니다. –

+1

새 라우터를 작동시킬 수 없어서 @ angular/router-deprecated로 되돌 렸습니다.이 작업을 위해이 링크가 도움이된다는 것을 알았습니다. http://stackoverflow.com/questions/ 37000243/angular2-router-deprecated-dependencies-not-loading-loaded. – Dan