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

router.isActive and routerLinkActive to support more options #13205

Closed
vsavkin opened this issue Dec 2, 2016 · 41 comments
Closed

router.isActive and routerLinkActive to support more options #13205

vsavkin opened this issue Dec 2, 2016 · 41 comments

Comments

@vsavkin
Copy link
Contributor

@vsavkin vsavkin commented Dec 2, 2016

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
@artaommahe
Copy link
Contributor

@artaommahe artaommahe commented Jan 18, 2017

@vsavkin what about intersection option for isActive method?
I have this route

/:slug/chat
// /user1/chat
// /user2/chat

And need to check that current url is any of them. I would be cool to has intersection mode check like this

// current url /user1/chat
// route segments [ '/user1', 'chat' ]
router.isActive([ null, 'chat' ], { type: 'intersection' })  === true

more complex example route

// route /:param1/static1/:param2/static2

// url /123/static1/456/static2
router.isActive([ null, 'static1', null, 'static2' ], { type: 'intersection' })  === true
router.isActive([ null, null, 456, 'static2' ], { type: 'intersection' })  === true
router.isActive([ null, 'static1', 456 ], { type: 'intersection' })  === true
@doorman02
Copy link

@doorman02 doorman02 commented Feb 2, 2017

What is the current state of this. Is it possible to ignore/exclude query parameters when routerLinkActiveOptions is set to exact?

@DzmitryShylovich
Copy link
Contributor

@DzmitryShylovich DzmitryShylovich commented Feb 2, 2017

ignore/exclude query parameters when routerLinkActiveOptions is set to exact?

nope

What is the current state of this

it will be a part of 4.0 release

@doorman02
Copy link

@doorman02 doorman02 commented Feb 2, 2017

Ok thanks for the info, do you know when v4 will be released approx?

@DzmitryShylovich
Copy link
Contributor

@DzmitryShylovich DzmitryShylovich commented Feb 2, 2017

march-april

@doorman02
Copy link

@doorman02 doorman02 commented Mar 24, 2017

Hi @DzmitryShylovich do you know if Include/exclude queryParams is included in the new v4 release?

@DzmitryShylovich
Copy link
Contributor

@DzmitryShylovich DzmitryShylovich commented Mar 24, 2017

@doorman02 nope, it wasn't included. there were more important tasks.

@doorman02
Copy link

@doorman02 doorman02 commented Mar 24, 2017

Ok, thanks just checking :)

@overflew
Copy link

@overflew overflew commented May 9, 2017

Can this also include similar handling for secondary routes?

E.g.: Some way that .isActive('/profile/home') would return true when on '/profile/home(modal:confirmation)'.

I have a plnkr + detail here: http://stackoverflow.com/questions/43647979/angular-router-should-isactive-identify-the-main-route-when-a-secondary-rou

@nthypes
Copy link

@nthypes nthypes commented Jul 13, 2017

News on this ?

@tytskyi
Copy link

@tytskyi tytskyi commented Jul 13, 2017

@antonioasmoura nothing changed, docs: https://angular.io/api/router/RouterLinkActive

@devforey
Copy link

@devforey devforey commented 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);
}
@webdeveloperninja
Copy link

@webdeveloperninja webdeveloperninja commented Dec 2, 2017

Any news on this?

@webdeveloperninja
Copy link

@webdeveloperninja webdeveloperninja commented Dec 2, 2017

Im on angular 5 still have to use this hack?

@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2018
@xMarkusSpringerx
Copy link

@xMarkusSpringerx xMarkusSpringerx commented Jan 25, 2018

Any news about this topic? I would also need the possibility to set a route to active which some restrictings etc.

/store/ui/
/store/ui/new
/store/ui/news
/store/ui/friends

I would need sth like an ignore where I can set that the /store/ui should be ignored while evaluating the current active route.

@Saonela
Copy link

@Saonela Saonela commented Mar 6, 2018

Still waiting... This is really annoying

@anuragd7
Copy link

@anuragd7 anuragd7 commented Mar 15, 2018

+1

2 similar comments
@TobiasMalikowski
Copy link

@TobiasMalikowski TobiasMalikowski commented Apr 21, 2018

+1

@cakeinpanic
Copy link

@cakeinpanic cakeinpanic commented May 7, 2018

+1

@sirBlond
Copy link

@sirBlond sirBlond commented May 14, 2018

Here's my workaround :) similar to what @devforey offered, but it uses Router class instead of ActivatedRoute so that it could work from child component.

public isLinkActive(url) {
    let charPos = this.router.url.indexOf('?');
    let cleanUrl = charPos !== -1 ? this.router.url.slice(0, charPos) : this.router.url;
    return (cleanUrl === url);
}
@gozeon
Copy link

@gozeon gozeon commented May 29, 2018

see doc & see example

@sayax
Copy link

@sayax sayax commented May 29, 2018

Or you could just use QueryParamsHandling="merge" which solves the problem

@tinyweasel
Copy link

@tinyweasel tinyweasel commented May 29, 2018

Why isn't this sorted yet on 5? Seems like a fairly common use case.

@Halfist
Copy link

@Halfist Halfist commented Jun 18, 2018

Was this added in Angular 6?

atscott added a commit to atscott/angular that referenced this issue Jan 4, 2021
This commit adds more configurability to the `Router#isActive` method.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205
atscott added a commit to atscott/angular that referenced this issue Jan 4, 2021
This commit adds more configurability to the `Router#isActive` method.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205
atscott added a commit to atscott/angular that referenced this issue Jan 4, 2021
This commit adds more configurability to the `Router#isActive` method.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205
atscott added a commit to atscott/angular that referenced this issue Jan 4, 2021
This commit adds more configurability to the `Router#isActive` method.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205
atscott added a commit to atscott/angular that referenced this issue Jan 5, 2021
This commit adds more configurability to the `Router#isActive` method.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205
atscott added a commit to atscott/angular that referenced this issue Jan 5, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205
atscott added a commit to atscott/angular that referenced this issue Jan 5, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Jan 5, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Jan 11, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Jan 11, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Jan 11, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Jan 11, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Jan 11, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Jan 12, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
@sviat9440
Copy link

@sviat9440 sviat9440 commented Jan 12, 2021

Any news?

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Jan 12, 2021

@sviat9440 - this issue is being dealt with by @atscott in #40303

atscott added a commit to atscott/angular that referenced this issue Feb 12, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Feb 12, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Feb 16, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Feb 16, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Feb 16, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Feb 23, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Feb 24, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
atscott added a commit to atscott/angular that referenced this issue Feb 24, 2021
This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.
@zarend zarend closed this in 6c05c80 Feb 24, 2021
twerske added a commit to twerske/angular that referenced this issue Feb 26, 2021
angular#40303)

This commit adds more configurability to the `Router#isActive` method
and `RouterLinkActive#routerLinkActiveOptions`.
It allows tuning individual match options for query params and the url
tree, which were either both partial or both exact matches in the past.
Additionally, it also allows matching against the fragment and matrix
parameters.

fixes angular#13205

BREAKING CHANGE:
The type of the `RouterLinkActive.routerLinkActiveOptions` input was
expanded to allow more fine-tuned control. Code that previously read
this property may need to be updated to account for the new type.

PR Close angular#40303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.