[英]Angular unwanted reload page
當我單擊 routerLink 時,它會轉到鏈接頁面並重新加載整頁(又名父組件刷新)
我嘗試制作第二個 app-routing.module,如下例所示: https://angular.io/guide/router-tutorial-toh但它並沒有解決問題。 既不使用路由器插座名稱。 我沒有想法了
我的路線是這樣的:
const routes: Routes = [
{
path: 'account',
component: StandardLayoutComponent,
canActivate: [AuthGuard],
children: [
{ path: 'schools', component: SchoolsComponent },
{
path: 'contacts',
component: ContactsComponent,
},
{
path: 'dashboard',
component: DashboardComponent,
},
],
},
{
path: ':schoolSlug',
component: RegistrationLayoutComponent,
children: [
{
path: 'login',
component: LoginComponent,
},
{
path: 'forgot_password',
component: ForgotPasswordComponent,
}
],
},
{ path: '**', redirectTo: 'account/dashboard', pathMatch: 'full' },
];
側導航組件 html:
<div
class="d-flex flex-row mb-3 pointer lightHover"
[routerLink]="['dashboard']"
>
<div class="align-self-center col-md-3 pr-0 text-center">
<img src="/assets/img/icons/squares.svg" />
</div>
<div class="col-md-9">
<h6 class="font-weight-bold text-gray-dark mb-1 pt-3">
{{ "MENU.ANALYSE.TITLE" | translate }}
</h6>
<p class="sidenav-txt pb-3">
{{ "MENU.ANALYSE.DESCRIPTION" | translate }}
</p>
</div>
</div>
<div
class="d-flex flex-row mb-3 pointer lightHover"
[routerLink]="['contacts']"
>
<div class="align-self-center col-md-3 display-5 pr-0 text-center">
<img src="/assets/img/icons/user.svg" />
</div>
<div class="col-md-9">
<h6 class="font-weight-bold text-gray-dark mb-1 pt-3">
{{ "MENU.CONTACTS.TITLE" | translate }}
</h6>
<p class="sidenav-txt pb-3">
{{ "MENU.CONTACTS.DESCRIPTION" | translate }}
</p>
</div>
</div>
我在 app.component 中有一個路由器插座,在 standardLayoutComponent 中有一個(我在其中也調用 header 和 sidenav)例如,當我單擊從“/account/dashboard”到“/account/contacts”的路由器鏈接時,standardLayoutComponent 刷新(使用 header 和 sidenav) 而不是僅刷新 DashboardComponents
感謝您的幫助(使用最新版本的角度)
好的,我終於解決了這個問題。 我通過傾倒我的組件來查看問題是否來自它們。
就是這行代碼:
constructor (
...
){
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.