routerLink inside <mat-tab> angular material

Deepak picture Deepak · Dec 25, 2017 · Viewed 34.8k times · Source
<a routerLink="/add"></a><mat-tab label="Add Identity"></mat-tab>

or

<mat-tab label="Add Identity"> <a routerLink="/add"></a></mat-tab>.

I am new to Angular, Trying to use routing with the above Angular material component.

But it's not appending the URL when I am clicking on the Home tab. Any help on this.

Answer

Hannah C picture Hannah C · Feb 3, 2018

you can actually combine them into one like this:

<a mat-tab-link [routerLink]="/add">Add Identity</a>

you'll also need to make sure you're using <nav mat-tab-nav-bar>, instead of <mat-tab-group>.

documentation here: https://material.angular.io/components/tabs/overview#tabs-and-navigation