[英]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.