简体   繁体   English

导航到子组件时父组件重新初始化

[英]Parent component getting re-initialised when navigating to child component

Please help me.请帮我。
I have problem with second router for children我有第二个儿童路由器的问题
My routes:我的路线:

const routes: Routes = [
  {path: '', pathMatch: 'full', redirectTo: 'login'},
  {
    path: 'web', component: WebComponent,
    children: [
      {path: 'about', component: AboutComponent},
      {path: 'skills', component: SkillsComponent},
    ]
  }
]

AboutComponent is without module. AboutComponent 没有模块。
In WebComponent I have button:在 WebComponent 我有按钮:

<nav>
    <button [routerLink]="'/web/about'" (click)="clickButton()" [ngClass]="{animationStart: anim > 4}">About me</button>
</nav>
<div class="root">
    <router-outlet></router-outlet>
</div>

When I click this button, I have some problem.当我点击这个按钮时,我遇到了一些问题。 The ngOnInit in WebComponent restart. WebComponent 中的 ngOnInit 重启。 Why?为什么? I don't want this, because also the animation is running again.我不想要这个,因为 animation 也再次运行。 Please help me.请帮我。

GitHub: https://github.com/ZakuroPL/webCV/tree/main/src/app GitHub: https://github.com/ZakuroPL/webCV/tree/main/src/app

I am not sure why is it refreshing whole web component, but what I know, if you have children routes, you don't have to call them like [routerLink]="'/web/about'" , it would be enough to use about only and normally, you should provide to router link an array, so maybe that is actually refreshing your page我不确定为什么它会刷新整个 web 组件,但据我所知,如果你有子路由,你不必像[routerLink]="'/web/about'"这样调用它们,就足够了仅使用about并且通常情况下,您应该为路由器链接提供一个数组,所以也许这实际上是在刷新您的页面

Try it like this [routerLink]="['about']" and see what is going to happen像这样尝试[routerLink]="['about']"看看会发生什么

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重新初始化组件时,AGM 是否保留 Google Map 的 session? - Does AGM preserve Google Map's session when component is re-initialised? Angular 子组件在父 oninit 期间父函数未初始化 - Angular child component not initialised when parent is function during parent oninit 从子组件(角度)导航时更新父组件 - Update parent component when navigating from child Component (Angular) 组件未在路由器navigating上初始化。仅在浏览器刷新时才初始化? - component not initialised on router navigating.it initialising only when browser refreshes? 父属性更改时如何不重新初始化子组件? - How to not re-initialise child component when parent property changes? 不导航到子组件 - Not navigating to Child Component 子级初始化之后,子级DOM上父组件的操作导致ExpressionChangedAfterItHaHasBeenCheckedError - After child has been initialised, operation from parent component on child DOM causes ExpressionChangedAfterItHasBeenCheckedError 触发子组件事件时如何调用父组件构造函数 - How is the parent component constructor getting called when child component event is triggered Angular 6使用懒惰laoding访问父组件的子组件时发生意外行为 - Angular 6 Unexpected behavior when getting access to child component of a parent component using lazy laoding 尝试将数据从子组件传递到父组件时出现错误“ NavController没有提供者” - Getting the error “No provider for NavController” when trying to pass data from child component to parent component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM