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.

router.isActive and routerLinkActive to support more options

See original GitHub issue

Currently router.isActive and routerLinkActive support only one option exact:boolean.

When exact = true, isActive will return true if:

  • queryParams match exactly
  • the url has the same url segments with all “path” equal
  • matrix params are ignored

When exact = false, isActive will return true if:

  • The queryParams of the containee is a subset of the queryParams of the container
  • The url tree of the containee is a subtree of the url tree of the container
  • Matrix params are ignored

We should replace the exact=true with a string type that supports more options:

  • Include/exclude queryParams
  • Include/exclude fragment
  • Include/exclude matrix params

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:203
  • Comments:42 (6 by maintainers)

github_iconTop GitHub Comments

40reactions
devforeycommented, Sep 7, 2017

A workaround for ignoring the queryParams for routerActive with exact: true would be to create your own condition to check if the current URL without the query params is equal to the routerLink.

<a routerLink="/my-link" [class.active]="isLinkActive('/my-link')"></a>
public isLinkActive(url: string): boolean {
  return (('/' + this.activatedRoute.snapshot.url.join('/')) === url);
}
15reactions
Saonelacommented, Mar 6, 2018

Still waiting… This is really annoying

Read more comments on GitHub >

github_iconTop Results From Across the Web

RouterLinkActive - Angular
Options to configure how to determine if the router link is active. ... You can set more than one class using a space-separated...
Read more >
In Angular, how do you determine the active route?
With the new Angular router, you can add a [routerLinkActive]="['your-class-name']" attribute to all your links: <a [routerLink]="['/home']" ...
Read more >
New Angular Router features in versions 7, 8, and 9 - Medium
Catch up on the latest Angular Router features: Dynamic imports to lazy load modules, advanced route guards, routerLinkActive improvements.
Read more >
What's new in Angular 12.0? - Ninja Squad
routerLinkActive has more fine-tuned options. The router offers a directive called routerLinkActive to add a CSS class to the link if it points ......
Read more >
Mastering RouterLink - Briebug Blog
The RouterLink directive translates the given route into an href ... There is another, more flexible syntax for routes: the "array" syntax.
Read more >

github_iconTop Related Medium Post

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