【发布时间】:2019-04-10 21:54:35
【问题描述】:
我有多个共享同一个组件的子组件,它们工作正常,但是,我无法在页面之间路由,因为 Angular 怀疑该组件已经加载。尝试路由到这些子路由时是否可以重新加载组件?
const ServicesRouting: ModuleWithProviders = RouterModule.forChild([
{
path: '',
component: StructureComponent,
canActivate: [AuthGuard],
children: [
{
path: 'services',
canActivate: [AuthGuard],
component: servicesComponent,
children: [
{
path: 'one',
canActivate: [AuthGuard],
component: servicesComponent,
},
{
path: 'two',
canActivate: [AuthGuard],
component: servicesComponent,
},
{
path: 'three',
canActivate: [AuthGuard],
component: servicesComponent,
},
{
path: 'four',
canActivate: [AuthGuard],
component: servicesComponent,
}
]
}
]
}
]);
【问题讨论】:
-
看起来 AuthGaurd 阻止了它,删除 Gaurd 并检查
-
如果它们共享相同的组件,我不确定为什么要为每个路由创建不同的页面。你可以使用像
path: 'home/:id'这样的参数。 -
@GreatHawkeye 你有一个非常公平的观点(感觉像个白痴)。我会做出相应的更改并回复您。
-
@GreatHawkeye 我已经更新了路由以包含 /:service,但是,尝试路由时组件的内容保持不变。
标签: angular typescript angular6 angular-routing