2017-02-09 13 views
3

모달 창에 보조 경로를 사용하려고합니다. 내가 시도한 것에 관계없이 해결할 수는 없습니다. 방금 라우팅 오류가 발생합니다. 여기 내 접근 ...각도 2 라우터가 하위 보조 경로를 해결하지 않습니다.

app.component.html

<router-outlet></router-outlet> 
<router-outlet name="modal"></router-outlet> 

관리 - routing.module.ts

... 
const ROUTES: Routes = [ 
    { 
    path: 'admin', 
    component: AdminComponent, 
    children: [ 
     { 
     path: 'accounts', 
     loadChildren: './accounts/accounts.module#AccountsModule' 
     },{...} 
    ] 
    } 
]; 
... 

계정-routing.module.ts입니다

... 
const ROUTES: Routes = [ 
    { 
    path: '', 
    children: [ 
     { 
     path: '', 
     component: AccountsIndexComponent 
     },{ 
     path: 'new', 
     component: AccountsNewComponent 
     },{ 
     path: ':id', 
     component: AccountsShowComponent 
     },{ 
     path: ':id/edit', 
     component: AccountsEditComponent, 
     outlet: 'modal' 
     } 
    ] 
    } 
]; 
... 

modal.service.ts

... 
    constructor(
    private router:Router, 
    private route:ActivatedRoute 
) { } 
    open(route:Array<any>) { 
    this.router.navigate(
     [{outlets: {drawer: route}}], {relativeTo: this.route} 
    ) 
    } 
    ... 

나는 그것이 내가 그것을 어떻게 해야하는 생각 무엇 /admin/accounts(modal:1/edit)로 이동하려고 ModalService.open([account.id, 'edit']) 전화. 하지만 난 그냥 1/edit URL 세그먼트와 일치하지 않는 오류가 발생합니다.

NavigationError(id: 2, url: '/admin/accounts(modal:1/edit)', error: Error: Cannot match any routes. URL Segment: '1/edit') 

나는 다음을 시도하고 그들은 ... 중 하나가 작동하지 않았다

ModalService.open(['accounts', account.id, 'edit']) 
ModalService.open(['admin','accounts', account.id, 'edit']) 
+0

정확히 동일한 문제가 발생합니다. 해결책을 찾았습니까? –

+0

절대로하지 않았습니다. 우리는 포기하고 ng-bootstrap 라이브러리 – Brian

답변

2

이로드되지 아동 보조 경로를 방지 라우터에 known bug가있는 것 같다 때 부모 경로는 accounts-routing.module.ts에서 무엇을하고 있는지, 이는 비어 :

const ROUTES: Routes = [ 
    { 
    path: '',     // <--- cannot have an empty parent path... 
    children: [ 
     { 
     path: ':id/edit', 
     component: AccountsEditComponent, 
     outlet: 'modal'  // <--- ...with child aux outlet 
     } 
    ] 
    } 
] 

이 문제를 해결하려면, 우리는 경로에 대해 무언가를 제공해야합니다. 여기

this.router.navigateByUrl('accounts/(modal:1/edit)') 

가 있습니다 :

<a [routerLink]="['accounts', {outlets: {'modal': ['1/edit']}}]"> 

또는 프로그래밍 방식 :

const ROUTES: Routes = [ 
    { 
    path: 'accounts', 
    ... 

은 당신이 routerLink에서 하나 귀하의 보조 경로를 탐색 할 수 있습니다 : 예를 들어, 당신은 당신의 경로 'accounts' 이름을 경우 working Plunkr 이것을 알아 내고 자식 보조 경로를 성공적으로로드하는 방법을 보여줍니다.

+1

Ugh를 사용하여 모달을 표시하기로 결정했습니다. 이 문제는 내가 포기하기 전에 하루나 이틀 동안 내 엉덩이를 찼습니다. 이 문제가 해결 될 때까지 나는 다른 접근 방식으로 붙어있는 것처럼 보입니다. 우리의 앱은 너무 커서 한 기능에 대한 지연로드를 떨어 뜨릴 수 없습니다. @Mike Chamberlain에게 감사의 말을 전합니다! – Brian

+0

게으른 로딩을 정말로 중단해야합니까? 게으른로드 된 모듈에 추가 (의미없는) URL 세그먼트를 포함하는 것만으로는 충분하지 않습니까? 새로운 계정 경로는'/ admin/accounts/dummy/new'와 같을 것입니까? 못 생겼어.하지만 효과가 있을까? –

+0

그래, 그게 효과가 있지만 내 생각에는 좀 못생긴 것 같아. :)이 시점에서 라우터가 고정되면 부트 스트랩 모달과 리팩토링 기능을 고수 할 것 같아. – Brian