2016-08-03 98 views

回答

1

你可以做到這一點,你只需要保持正確的順序路線,

像下面看到a/b/c到來之前a/b,意味着完全合格的路徑應該是第一位的。

export const routes: RouterConfig = [ 
    { path: 'a/b/c', component: ABC }, 
    { path: 'a/b', component: AB } 
    ]; 

    @Component({ 
    selector: 'my-app', 
    template: ` 
    <h1 class="title">Component Router</h1> 
    <nav> 
     <a routerLink="https://stackoverflow.com/a/b" routerLinkActive="active">a/b</a> 
     <a routerLink="https://stackoverflow.com/a/b/c" routerLinkActive="active">a/b/c</a> 
    </nav> 
    <router-outlet></router-outlet> 
    `, 
    directives: [ROUTER_DIRECTIVES] 
    }) 
    export class AppComponent { 
    } 

    @Component({ 
    selector: 'my-abc', 
    template: ` 
     <h1>a-b-c</h1> 
    ` 
    }) 
    export class ABC { 
    } 

    @Component({ 
     selector: 'my-ab', 
     template: ` 
     <h1>a-b</h1> 
     ` 
    }) 
    export class AB { 
    } 

這裏是Plunker!

希望這有助於!

+1

訂單在最新的路由器版本中不再重要。 –

+0

http://onehungrymind.com/named-router-outlets-in-angular-2/ – Sonne