【发布时间】:2017-02-01 23:16:26
【问题描述】:
我在应用的根路由模块中使用以下路由:
const routes: Routes = [
{
path: '',
children: [
{
path: 'home',
component: HomeDetailsComponent,
},
{
path: 'home',
component: HomeDetailsComponent,
children: [
{
path: 'room/:id',
component: RoomDetailsComponent,
},
]
},
{
path: 'sectorNumber',
component: SectorNumberComponent
},
{
path: '**',
redirectTo: 'home',
},
]
}
];
现在,在 HomeDetailsComponent 内部,我使用 OnInit 生命周期挂钩来调用 http get 方法,并在此基础上进行一些事件处理。但是,我注意到通过这种路由,我的 HomeDetailsComponent 被初始化了两次。一次当我导航到'http://localhost:3000/#/curriculum/' 时,第二次当我导航到'http://localhost:3000/#/curriculum/chapter/1' 路线时。谁能告诉我为什么会这样?
【问题讨论】: