我有一个父路由,下面我有我的子路由,如下所示。
const routes : Routes = [
{path: 'home', component: HomeComponent,
children: [
{ path: 'airetail', component: AiretailplatformComponent},
{ path: 'cpr', component: CprComponent },
{ path: 'snap', component: SnapComponent},
{ path: 'others', component: OthersComponent },
{ path: 'docs', component: DocumentationComponent },
{path: 'dynamic', component: AiRetailDynamicComponent}
],
{path: '', redirectTo: '/home', pathMatch: full}
}
]
每当我在任何子路由中并尝试重新加载任何子路由组件时,父路由也会被调用。有没有一种方法可以在我重新加载子路由页面时限制调用我的父路由,这里是HomeComponent?
发布于 2021-03-01 18:46:35
使用相对路线。
在你的.component.ts中
constructor(
private activateRoute: ActivatedRoute,
private router: Router) {
routeToPath() {
this.router.navigate(['<your-path>'], { relativeTo: activateRoute
})
}
}
这将仅加载子路由。
https://stackoverflow.com/questions/66427763
复制