Angular 4 - 带孩子的路线不起作用

时间:2017-04-18 19:02:20

标签: angular typescript angular2-routing

您好我有以下路线结构:

export const routes: Routes = [
  {
    path: 'site', component: MainViewComponent, pathMatch: 'full',
    children: [
      { path: '', redirectTo: 'extra-details', pathMatch: 'full'},
      { path: 'extra-details', component: ExtraDetailsViewComponent}    
  ]},
  { path: 'login', component: LoginViewComponent, pathMatch: 'full' },
  { path: '**', component: PageNotFoundComponent }
];

登录和404(找不到页面)都很有效,问题是当我尝试访问/ site时,它被重定向到/ site / extra-details,但它显示404视图。当我评论' **'路径我收到以下错误:

  

错误:无法匹配任何路线。网址细分:'网站/额外细节'

我错过了什么?

谢谢, 马坦

1 个答案:

答案 0 :(得分:2)

只有在重定向时才需要

pathMatch,在已定义组件的位置删除它。