Demo
To see how the anchor is changing during navigation through tabs open the demo in a new window.
Writing logic to sync a tab with an anchor
We can move all logic related to synchronizing the opened tab with hash to directive. Thanks of that our solution will be very easy to use in other places.
Take a look at how the directive works. First, the directive checks if a tab has label
.
If not the directive will create a fake ID with the pattern tab-{index}
.
How to use
To use the directive just add the selector to a component.
Do not forget to import the directive to your component/module.
You cannot have more than one mat-tab-group
on the page. To get a deal with it you should rewrite logic to save the opened tab in another place (for example in query params).