I've the following children routes:
{ path: '', component: LoginSingupComponent,
children: [
{ path: 'login', component: LoginComponent },
{ path: 'singup', component: SingupComponent },
]
},
Navigating to /login
or /singup
works ok (correct Component is loaded).
This is a excerpt from LoginSingupComponent
<nav md-tab-nav-bar class="mb-1">
<a md-tab-link routerLink="/login" routerLinkActive [routerLinkActiveOptions]="{exact: true}" #rla="routerLinkActive" [active]="rla.isActive">Entrar {{rla.isActive}}</a>
<a md-tab-link routerLink="/singup" routerLinkActive [routerLinkActiveOptions]="{exact: true}" #rla="routerLinkActive" [active]="rla.isActive">Criar uma conta{{rla.isActive}}</a>
</nav>
When on /login
all rla.isActive == false
when on /singup
all rla.isActive == true
Tried with and without exact: true
RouterLinkActivelinkTracks whether the linked route of an element is currently active, and allows you to specify one or more CSS classes to add to the element when the linked route is active.
A child route is like any other route, in that it needs both a path and a component . The one difference is that you place child routes in a children array within the parent route.
routerLinkActive is simply an indicator of whether this link represents the active route. @jessepinho - Tried it - [routerLinkActive]="'active'" will only work if you also have [routerLink] in the a-tag. If you had (click)="navitageTo('/route')" instead of [routerLink], and in that function, you called this.
Try like this :
<nav md-tab-nav-bar class="mb-1">
<a md-tab-link [routerLink]="['/']" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">Home</a>
<a md-tab-link [routerLink]="['/login']" routerLinkActive="active">Login</a>
<a md-tab-link [routerLink]="['/singup']" routerLinkActive="active">Signup</a>
</nav>
Found the problem.
It's was because i was exporting both rounterLinkActive with same variable name which causes this weired behavior.
<a md-tab-link routerLink="/auth/login" routerLinkActive [active]="rlal.isActive" #rlal="routerLinkActive">Entrar {{rlal.isActive}}</a>
<a md-tab-link routerLink="/auth/singup" routerLinkActive [active]="rlas.isActive" #rlas="routerLinkActive">Criar uma conta{{rlas.isActive}}</a>
Solves the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With