我的路线如下所示。当用户使用URL加载应用程序时 - > http://localhost:4200/will-kit 我只获得了TABS,并且没有看到默认加载的第一个标签
点击开始标签后,标签会打开,网址将为 - > http://localhost:4200/will-kit/(taboutlet:./start)
const routes: Routes = [ { path: 'will-kit', component: WillKitLayoutComponent, children: [
{
path: '',
redirectTo: './start',
pathMatch: 'full'
},
{
path: './start',
component: StartComponent,
outlet: 'taboutlet'
},
{
path: './you',
component: YouComponent,
outlet: 'taboutlet'
},
{
path: './status',
component: StatusComponent,
outlet: 'taboutlet'
} ]} ];
以HTML格式标记代码
<nav mat-tab-nav-bar>
<a mat-tab-link class="mat-test" *ngFor="let routeLink of routeLinks; let i = index;" [routerLink]="[{outlets: {taboutlet: routeLink.link}}]"
routerLinkActive #rla="routerLinkActive"
(click)="activeLinkIndex = i" [active]="rla.isActive" [routerLinkActiveOptions]="{exact: true}">
<label class="mat-subheading-1">{{routeLink.label}} </label>
</a>
</nav>
答案 0 :(得分:1)
您可以使用AfterViewInit
功能默认打开第一个标签
答案 1 :(得分:0)
按照建议在AfterViewInit中处理路线,这是默认加载第一个标签
public ngAfterViewInit() {
this.router.navigate([{ outlets: { 'taboutlet': './start' } }], {
relativeTo: this.route
});
}