I want to use Angular Material tabs https://material.angular.io/components/tabs with a router navigation in the tabs.
I tried to use <nav mat-tab-nav-bar>
as indicated in the doc, and I found this tutorial: https://nirajsonawane.github.io/2018/10/27/Angular-Material-Tabs-with-Router/
where I can find a template like that:
<nav mat-tab-nav-bar>
<a mat-tab-link
*ngFor="let link of navLinks"
[routerLink]="link.link"
routerLinkActive #rla="routerLinkActive"
[active]="rla.isActive">
{{link.label}}
</a>
</nav>
<router-outlet></router-outlet>
But the problem is, that my tabs are not at the root of my application, but are in a submodule in a child route. I have something like that:
In app-routing-module:
const routes: Routes = [
...
{ path: 'subpath', loadChildren: () => import('./path-to-module/submodule.module').then(m => m.SubmoduleModule) },
...
];
In submodule-routing-module I should have something like that:
const routes: Routes = [
{ path: '', component: FirstTabComponent },
{ path: 'tab2', component: SecondTabComponent },
]
What I would like is that, if I go to url /subpath
I see the tabs with the first tab selected, and if I go to url /subpath/tab2
I see the tabs with the second tab selected.
Any idea how to do that?