1

When I reload/refresh my app the routes in the menubar are displayed and all of the items are set to active. I have configured for the Routes:

export const routes: Routes = [
  {
    path: '', pathMatch: 'full', redirectTo: 'home',
    data: { title: undefined }
  },
  {
    path: 'login', component: LoginComponent,
    data: { title: 'Login' }
  },
  {
    path: 'home', component: MainComponent,
    data: { title: 'Home' }
  },
  {
    path: 'search',  component: SearchListComponent,
    data: { title: 'Search'}
  },
];

In my menu-bar I have reduced the code to the following:

<div class="container">
    <a routerLinkActive="is-active" 
       routerLink="/login">Login</a> |
    <a routerLinkActive="is-active" 
       routerLink="/search">MySearch</a> |
    <a routerLinkActive="is-active" 
       routerLink="/home">MyHome</a> |
</div>

<div >
  <div *ngFor="let route of router.config">
    <a routerLinkActive="is-active" 
        [routerLink]="userName? ('/'+route.path ): '/' ">{{route.data.title}}... {{userName? ('/'+route.path ): '/' }} </a> |
  </div>
</div>

which includes my routes twice - nearly identical - except that the second code generates the items dynamically. The first one selects the items properly after a refresh while the second one fails.

According to the docu routerLink can be used as string

Anybody could explain me why the second one fails?

EDIT: As requested a picuture

enter image description here

but the content remains the same after I have chosen another link! Than all links are rendered properly!

EDIT2

I was able to reproduce the error. Main issue is that the evaluation of the routerlink was done too late and I run into the same issue like on the already reported bug.

My current workaround solution: initially set the userName :-/

LeO
  • 4,238
  • 4
  • 48
  • 88

1 Answers1

0

Try adding [routerLinkActiveOptions]="{ exact: true }" to your generated links. By default Angular router will match any part.

Zlatko
  • 18,936
  • 14
  • 70
  • 123
  • Tried, but the effect remains the same :-/ I guess it has to do with the rendering which isn't called again.... – LeO Dec 13 '18 at 15:58