我有一个
HTML
代码:
<table mat-table [dataSource]="claims" matSort class="mat-elevation-z8">
<ng-container *ngFor="let column of displayedColumns" [matColumnDef]="column">
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{ titleCase(column) }}</th>
<td mat-cell *matCellDef="let element">
<ng-container *ngIf="column === 'claimID'; else defaultCell">
<a href="#" (click)="onClaimIdClick(element[column])">
{{ element[column] }}
</a>
</ng-container>
<ng-template #defaultCell>
{{ getElementValue(element, column) }}
</ng-template>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
我补充道,它正确加载了表格
click
功能到
claimId
列。
TS代码为:
onClaimIdClick(claimId: string): void {
console.log('Navigating to:', `/claims-summary/${claimId}`);
this.router.navigate(['/claims-summary', claimId]);
}
当我点击以下条目时
claimId
,它重定向到下一页,但调用了不匹配的路由。这是我的
app.routes.ts
.
import { Routes } from '@angular/router';
import { LoginComponent } from './components/login/login.component';
import { HomeComponent } from './components/home/home.component';
import { ClaimsSummaryComponent } from './components/claims-summary/claims-summary.component';
import { ClaimsInsightsComponent } from './components/claims-insights/claims-insights.component';
import { ClaimsComponent } from './components/claims/claims.component';
export const routes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'home', component: HomeComponent },
{ path: 'claims', component: ClaimsComponent },
{ path: 'claims-summary/:claimID', component: ClaimsSummaryComponent },
{ path: 'claims-insights/:type', component: ClaimsInsightsComponent },
{ path: '**', redirectTo: '', pathMatch: 'full' },
];
如果我打开新的url,http://localhost:4200/claims-summary/claimId在一个新的选项卡中,它可以完美加载。但当我试图通过以下方式导航到该页面时
onClick
,它重定向到
claim-summary
,但每次都调用不匹配的路由。我在这里错过了什么?