2016-05-06 133 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目前 –