question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

routerLinkActive does not updates on router.navigate to the same route

See original GitHub issue

Bug Report

Description

If we have some components that use router.navigate for the same route but with empty object or null for queryParams, then routerLinkActive directive does mark links as active. The use case to pass empty object is to pass some filters through query parameters to be able to share the link to the page.

Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-brrc3a Here we have 2 components with service provided for each component. Service performs the navigation using:

this.router.navigate(['.'], {
      queryParams: {},
      relativeTo: this.route
});

After this any link will not be marked as active. If reload the page with preset url (ex: /one), then the link will be marked. But navigation to another route will not remove active state from the link.

Your Environment

Angular Version:


Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1002.0
@angular-devkit/build-angular   0.1002.0
@angular-devkit/core            10.2.0
@angular-devkit/schematics      10.2.0
@angular/cdk                    10.2.7
@angular/cli                    10.2.0
@angular/material               10.2.7
@schematics/angular             10.2.0
@schematics/update              0.1002.0
rxjs                            6.5.4
typescript                      4.0.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
atscottcommented, May 25, 2021

@Airblader yep, pretty sure. The navigation from the service is triggered before the previous one completes.

0reactions
angular-automatic-lock-bot[bot]commented, Jun 25, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

routerLinkActive does not work with router.navigateByUrl or ...
I'm running into the same issue. I do a lot of processing when a user clicks a link and so I didn't use...
Read more >
RouterLinkActive - Angular
Tracks whether the linked route of an element is currently active, and allows you to specify one or more CSS classes to add...
Read more >
Angular Router: A Complete Guide
We are going to learn how the Angular Router nested routes functionality can be used to build a Bootstrap menu navigation system, ...
Read more >
Navigation • Angular - codecraft.tv
... how we can navigate between routes in Angular programmatically via the router ... The book and code has since been updated to...
Read more >
Angular (10) – Routing | Jerry's Blog - GitHub Pages
In the path, DO NOT add the slash / . ... routerLinkActive attribute can be added at the <a> tag or <li> tag,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found