我的父组件 html 有一些元素我需要在整个过程中保持不变,但会随着路由一起更改我的子组件,因此子组件加载正常但路由的更改没有得到反映[如果我尝试直接点击路由路径更改地址栏,它被渲染但没有父组件html元素存在]
父组件
`<parent-component>
<child1-component></child1-component>
<child2-component></child2-component>
<child3-component></child3-component>
//button for loading of child components which would be consistent
throughout in parent component along with child components being loaded
<button (click)="func()"></button>
</parent-component>`
父路由模块
`const routes: Routes = [
{ path: 'parentcomponent', component: parentComponent },
{ path: 'child1component', component: child1Component },
{ path: 'child2component', component: child2component },
{ path: 'child3component', component: child3component },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
在我的子组件中成功执行我的功能
子组件
`this.router.navigate[('pathofdesiredcomponent')]`
我尝试了正常路线和子路线,但它不起作用