Angular 2:导航到子默认路由不起作用

时间:2016-12-07 17:36:41

标签: angular angular2-routing

我的应用级别有一个导航栏,如下所示:

<ul>
<li id="navbar-header">Header</li>
<li class="navbar-item">
    <a routerLink="/administration"
       routerLinkActive="active">Administration</a>
</li>
<li class="navbar-item">
    <a routerLink="/web-report" routerLinkActive="active">Web Report</a>
</li>

我正在尝试设置我的网络报告路由的默认值,但由于某种原因它没有正确重定向并且它保留在localhost:8080 / web-report。

这是我的网络报告路由模块:

@NgModule({
imports: [
    RouterModule.forChild([
        {path: 'web-report', component: WebReportComponent, children : [
            {path: '', redirectTo: 'ticket-search', pathMatch: 'full'},
            { path: 'ticket-search',  component: TicketSearchComponent },
            { path: 'ticket-list/:simpleOrDetailed', component: TicketListComponent },
        ]}
    ])
],
exports: [
    RouterModule
]
})

如果需要,这是我的应用级路由:

@NgModule({
  imports: [
 RouterModule.forRoot([
        { path: '', redirectTo: 'administration', pathMatch: 'full' },
        { path: 'administration', component: AdministrationComponent},
        {path: 'web-report', component: WebReportComponent }
    ])],
   exports: [
RouterModule
  ]
 })

1 个答案:

答案 0 :(得分:0)

我能够弄清楚。我实际上需要在应用级别将路线更改为:

 {path: 'web-report', redirectTo: 'web-report/ticket-search', pathMatch: 'full'}