Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routerLinkActiveOptions fragment add option to not match when no fragment is used #54992

Open
mebibou opened this issue Mar 22, 2024 · 0 comments
Labels
area: router router: directives RouterLink, RouterLinkActive, RouterOutlet etc.
Milestone

Comments

@mebibou
Copy link

mebibou commented Mar 22, 2024

Which @angular/* package(s) are relevant/related to the feature request?

router

Description

Consider the following example:

import { IsActiveMatchOptions } from '@angular/router';

class MyComponent {
  protected routerLinkMatchOptions: IsActiveMatchOptions = {
    queryParams: 'subset',
    fragment: 'exact',
    paths: 'exact',
    matrixParams: 'ignored'
  }
}
<a routerLink="./" [routerLinkActiveOptions]="routerLinkMatchOptions" routerLinkActive="link-active"></a>
<a routerLink="./" fragment="fragment1" [routerLinkActiveOptions]="routerLinkMatchOptions" routerLinkActive="link-active"></a>

If you go on the page ./, only the first link will get the link-active class. If you go on ./#fragment1, both links will get the link-active class.

While that might be the desired effect for some, it is not necessarily always desired.

Proposed solution

Add another option to IsActiveMatchOptions.fragment, like exact-required, that would say:

  • if the link has the same fragment, it is a match
  • if the link has a different fragment or does not have a fragment, it is not a match

Which would differ from the current exact that behaves like:

  • if the link has the same fragment or does not have a fragment, it is a match
  • if the link has a different fragment it is not a match

Alternatives considered

Maybe this is a bug and the exact option should say "if there is no fragment, it is not exact, and therefore should not be a match"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: router router: directives RouterLink, RouterLinkActive, RouterOutlet etc.
Projects
None yet
Development

No branches or pull requests

2 participants