Here is a solution using the Location service that is not using the Angular Router and that listens to the hash fragment in the route and sets the selectedIndex to it, that way, the tabs content are all loaded in the same page but the activeTab will match the fragment set in the route.
The links to to go to the page and activate a tab would be /my-page#0
, /my-page#1
...
Here is a stackblitz: https://stackblitz.com/edit/mat-tab-sync-with-hash-fragment
import { Component } from '@angular/core';
import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
providers: [Location, { provide: LocationStrategy, useClass: PathLocationStrategy }]
})
export class AppComponent {
name = 'Angular';
selectedIndex = 0;
constructor(private location: Location) {
this.selectedIndex = (+this.location.path(true).substr(1) - 1) || 0;
this.location.subscribe((value: PopStateEvent) => {
if (value.url) {
this.selectedIndex = (+value.url.substr(1) - 1) || 0;
}
});
}
}
<mat-tab-group [selectedIndex]="selectedIndex">
...
Hope that helps.