Bug
Any active routerLinks with the md-tab-link directive should show the material design active styling
Paths with children and or relative paths seem to break the md-tab-nav-bar active styling (the individual tabs do not show the active styling when the corresponding route is active).
I created a repo reproducing the problem at: https://github.com/danwulff/md-tab-nav-bar-error-with-children
Steps to reproduce:
git clone https://github.com/danwulff/md-tab-nav-bar-error-with-children && cd md-tab-nav-bar-error-with-children && npm install && ng serveThe markup of the tabs is found within sub.component.html
@angular/cdk, @angular/material: 2.0.0-beta.8
Tested in Google Chrome 59
Without diving into your repo, did you look at using an exact route match?
https://angular.io/api/router/RouterLinkActive#routerLinkActiveOptions
<div routerLinkActive="active-link" [routerLinkActiveOptions]="{exact: true}">
<a routerLink="/user/jim">Jim</a>
<a routerLink="/user/bob">Bob</a>
</div>
I made a branch showing that routerLinkActive works when stripping the material stuff out: https://github.com/danwulff/md-tab-nav-bar-error-with-children/tree/pure-routerLink
$ git checkout pure-routerLink
Since I'm unsure, I'll leave this open until someone finds an issue to associate in @angular/router.
After poking around a bit more I think this may have to do with the routerLinkActive directive in the router module: https://angular.io/api/router/RouterLinkActive~~
I'm unsure if it currently supports relative paths. I'll do a little more research when I have time, which may be a while (who moves apartments in July blegh).
Just took a look and there are two issues with your markup:
md-tab-nav requires that only one tab is considered active at a time. This means that duplicating tabs for sub/ (or "one") will behave unexpectedly. So the first step is to be sure to only use a single tab for any unique route
In your master branch, you are redefining #rla for each tab. AFAIK the scope of this reference is template-wide, so really you're just overwriting it 3 times. Opt for using a unique template reference name for each tab or use *ngFor like below,
<nav md-tab-nav-bar>
<a md-tab-link *ngFor="let tab of tabs"
[routerLink]="[tab.path]"
routerLinkActive
#rla="routerLinkActive"
[routerLinkActiveOptions]="{exact: true}"
[active]="rla.isActive">
{{ tab.label }}
</a>
</nav>
tabs = [
{ path: './', label: 'one' },
{ path: 'two/123', label: 'two with param' },
{ path: 'two', label: 'two' }
]
I hope this helps!
Closing based on @willshowell's observations
Personally, using @willshowell's answer gives me errors.
ERROR Error: "Uncaught (in promise): Error: Template parse errors:
Can't bind to 'active' since it isn't a known property of 'a'. ("nk]="[tab.path]" routerLinkActive #rla="routerLinkActive" [routerLinkActiveOptions]="{exact: true}" [ERROR ->][active]="rla.isActive">
{{ tab.label }}
</a>
"): ng:///ComplaintDetailsModule/ComplaintDetailsComponent.html@1:152
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Just took a look and there are two issues with your markup:
md-tab-nav requires that only one tab is considered active at a time. This means that duplicating tabs for
sub/(or "one") will behave unexpectedly. So the first step is to be sure to only use a single tab for any unique routeIn your master branch, you are redefining
#rlafor each tab. AFAIK the scope of this reference is template-wide, so really you're just overwriting it 3 times. Opt for using a unique template reference name for each tab or use *ngFor like below,I hope this helps!