路由器子级组件未绑定

时间:2019-02-16 13:31:37

标签: typescript angular-ui-router angular6

我的路由器设置:

{
    path: "",
    component: DynamicContentComponent
  },
  { 
    path: ":ctype/:termid",   
    component: DynamicContentComponent,
    children: [    
      {

        path: "description/:nodeId" ,component: DescriptionContentComponent
      }
    ]
  }

];

我的链接与路由器(http://localhost:4200/restaurants/3025/description/2266)浏览器的地址栏匹配,但组件未加载(即DescriptionContentComponent,在加载时它将重定向到DynamicContentComponent

在这里

  

:ctype->餐馆
:termid-> 3025
:nodeId-> 2266

1 个答案:

答案 0 :(得分:0)

将您的路线更新为此

{ 
    path: ":ctype/:termid",   
    component: DynamicContentComponent,
    children: [    
       {
         path: "description/:nodeId" ,component: DescriptionContentComponent
       }
     ]
},
{
    path: "",
    component: DynamicContentComponent
}
  

路由在配置中的顺序很重要,这是设计使然。路由器在匹配路由时会使用“先赢”策略,因此应将更具体的路由放在不那么具体的路由之上。在上面的配置中,首先列出具有静态路径的路由,然后是与默认路由匹配的空路径路由。通配符路由排在最后,因为它匹配每个URL,并且只有在没有其他路由最先匹配时才应选择通配符路由。

在此处了解更多信息:Angular Routing