routerlink - Angular 2/4 - routerLinkActive not working properly -
i have problem routerlinkactive.
here 2 gifs explain.
- first problem: when start app, none of routerlinkactive give class active. if click on different route, finaly works.
- when click @ first on current route, class isn't displayed.
here code:
<ul class="nav"> <li *ngfor="let menuitem of menuitems" routerlinkactive="active" class="{{menuitem.class}}"> <a [routerlink]="[menuitem.path]"> <i class="material-icons">{{menuitem.icon}}</i> <p>{{menuitem.title}}</p> </a> </li> </ul>
here tree of route. (in red component called)
and route code:
import ... const routes : routes = [ { path: '', component: homecomponent, canactivate: [authguard], children: [ { path: 'dashboard', component: dashboardcomponent }, ..., { path: 'challenges', component: imagerankcomponent }, { path: 'niveau', component: levelcomponent }, { path: '', redirectto: 'dashboard', pathmatch: 'full' } ] } ]; @ngmodule({ imports: [routermodule.forchild(routes)], providers: [ { provide: locationstrategy, useclass: hashlocationstrategy } ], exports: [routermodule] }) export class homeroutingmodule {}
and menuitem is:
this.menuitems = routes.filter(menuitem => menuitem); const routes : routeinfo[] = [{ path: 'dashboard', title: 'dashboard', icon: 'dashboard', class: '' }, { path: 'challenges', title: 'tous les challenges', icon: 'dashboard', class: '' }, { path: 'niveau', title: 'niveau en ligne', icon: 'dashboard', class: '' }]
do know can problem?
edit:
i have tried:
absolute route. ie:
path: '/home/dashboard'
with
<a [routerlink]="menuitem.path">
and
<a [routerlink]="[menuitem.path]">
and result same. not working.
edit2:
adding:
[routerlinkactiveoptions]="{exact: true}" to:
<li *ngfor="let menuitem of menuitems" routerlinkactive="active" class="{{menuitem.class}} " [routerlinkactiveoptions]="{exact: true}">
doesnt resolve problem.
edit3:
the extension augury says me routerlink true route. class isn't activated in dom.
edit4:
so, have done exploration.
i have found if put menucomponent (sidebar) in parent root, working, active class displayed (but don't want put in parent)
edit5:
i have done plunker of situation... , plunker works... dont it.
try :
<li routerlinkactive="active" [routerlinkactiveoptions]="{exact: true}"> <a>home</a> </li>
Comments
Post a Comment