Let's say I'm at the Tab1 with the parameter id=1. Concretely the resulting url is http://localhost:4200/project/tab1;id=1. Now I click Tab2 and the url changes to http://localhost:4200/project/tab2. Is there a way to route the id too so that I get http://localhost:4200/project/tab2;id=1?
https://stackblitz.com/edit/angular-qzwzju
<nav mat-tab-nav-bar [backgroundColor]="'primary'">
<div mat-tab-link *ngFor="let link of navTabs" [routerLink]="link.link" routerLinkActive #rla="routerLinkActive"
[active]="rla.isActive">
{{link.label}}
</div>
</nav>
<router-outlet></router-outlet>
navTabs: NavTab[];
activeLinkIndex: number = -1;
constructor(private router: Router, private route: ActivatedRoute) {
this.navTabs = [
{ label: 'Tab1', link: './tab1', index: 0 },
{ label: 'Tab2', link: './tab2', index: 1 },
{ label: 'Tab3', link: './tab3', index: 2 },
];
}
ngOnInit(): void {
this.router.events.subscribe((res) => {
this.activeLinkIndex = this.navTabs.indexOf(this.navTabs.find((tab: NavTab) => tab.link === '.' + this.router.url));
});
}
export const appRoutes: Routes = [
{ path: 'tab1', component: Tab1Component },
{ path: 'tab2', component: Tab2Component },
{ path: 'tab3', component: Tab3Component },
];