Skip to content

routerLinkActive doesn´t set the active class correctly #54978

@MeMeMax

Description

@MeMeMax

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

No

Description

I use the router to have different layouts applied to different sections of my app. Therefore I have e.g. a route "with-frame" and children below it like this:

const routes: Routes = [
  {
    path: 'with-frame',
    component: LayoutComponent,
    children: [
      { path: '', redirectTo: 'container-queries/dashboard', pathMatch: 'full' },
      { path: 'container-queries/dashboard', component: DashboardComponent },
      { path: 'css-grid/dashboard', component: DashboardCssGridComponent }
    ]
  }
];

With this construct multiple routes are marked as active (as you can see in my demo repo).

For reproduction:

  • Get the demo repo
  • Execute npm i
  • Execute npm start

Please provide a link to a minimal reproduction of the bug

https://github.com/MeMeMax/router-link-active-bug

Please provide the exception or error you saw

No exception. Just wrong behaviour as seen in the reproduction demo. When initially opening the app multiple routes are marked as active in the top navigation. When I click around, they disappear as I visit every route once.

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.1.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions