2016-05-06 143 views
0

我工作的Angular2應用程序,我注意到孩子的路線不從父路線延伸。這是設計嗎?Angular2嵌套路由不正確的URL

例如,如果我有配置像這樣的路由父路由器:

// In top-level component 

router.config([ 
    new AsyncRoute({ 
     path: '/designer/:id', 
     name: 'Designer', 
     loader:() => 
      System.import('app/components/design.component') 
       .then(c => c['DesignComponent']) 
    }), 
    new AsyncRoute({ 
     path: '/planner/:id', 
     name: 'Planner', 
     loader:() => 
      System.import('app/components/plan.component') 
       .then(c => c['PlanComponent']) 
    }) 
]); 

和子路由器和路由在這些組件的定義如下所示:

// In child component, design.component for example 

router.config([ 
    new AsyncRoute({ 
     path: '/model', 
     name: 'Model', 
     loader:() => 
      System.import('app/design/components/model.component') 
       .then(c => c['ModelComponent']) 
    }) 
]); 

當頂-level加載頁面時我們可能會降落在http://localhost:5000/designer/10例如,但導航到孩子路由時,URL最終被http://localhost:5000/model而不是http://localhost:5000/designer/10/model

預計:

http://localhost:5000/designer/10/model 

實際:

http://localhost:5000/model 

回答

-1

在路徑子路由,則路徑需要與/...

new AsyncRoute({ 
     path: '/designer/:id/...', 
     name: 'Designer', 
     loader:() => 
      System.import('app/components/design.component') 
       .then(c => c['DesignComponent']) 

這結束也可能由以下原因造成異步路由。完整的URL只能在加載子組件後解決。這在Angular2新的路由器改變rc.0

+0

我嘗試這樣做,它不工作。實際上它根本不導航。父路由器是否在不使用'[routeLink]'的情況下安裝?另外,RC.0中有哪些變化?我將如何使用'router.navigate'最終導航到具有'/ ...'的路線? –

+0

你可以創建一個允許重現的Plunker嗎? –

+0

貝塔17目前 –