2016-07-25 77 views
2

我正在使用新的route3,并且想知道什么是URL语法以指定子路由的辅助组件。如何在angular2 router3中为子路由指定辅助组件

我有以下的孩子路由定义:

const router: RouterConfig = [ 
    { 
    path: 'component-c', component: ComponentC, children: [ 
     { path: 'auxPath', component: ComponentAux, outlet: 'aux'}, 
     { path: 'c1', component: ComponentC1 } 
    ] 
    } 
]; 

而对于ComponentC模板就像

@Component({ 
    selector: 'component-c', 
    template: ` 
    <div>Child Route Component</div> 
    <router-outlet></router-outlet> 
    <router-outlet name="aux"></router-outlet> 
    `, 
    directives: [ROUTER_DIRECTIVES] 
}) 

URL /组件-C/C1显示ComponentC1;然而,我已经尝试过像/组件-C的许多组合(AUX:auxPath)/ C1/组件-C/C1(AUX:auxPath)等,并且仍然不能找出如何让ComponentAux得到显示...

回答

3

你应该尝试形成像下面的URL。

this.router.navigateByUrl('/component-c/(c1//aux:auxPath) 

按我上次调查当前路由器版本在导航使用routerLinknavigate方法AUX插座的一些问题。您应该构建完整的URL并使用navigateByUrl

Plunker与example。点击详细按钮,然后点击管理。管理员在管理员中路由。全屏打开以查看URL形成。

的URL具有以下语义

  1. 儿童路径由/
  2. 如果路径的兄弟姐妹,那么它应该与括号包围分离()
  3. 同级由//
  4. 分离

    插座和路径被分隔:

    Parent/child/(gchild1//outletname:gchild2)

另外so question

+0

它的工作原理!也谢谢你的提示,我遇到与routerLink和导航方法相同的问题。 –

+0

@Arpit你可以将这个问题标记为重复的答案,我看到链接的答案几乎相同:) –

+0

事实上,两者都是我对答案的要求。我可以从下次看到。 –

相关问题