`routerLinkActive` and `router.isActive` do not work with arrays in queryParams.
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
routerLinkActive
and router.isActive
do not work with arrays in queryParams.
Expected behavior
routerLinkActive
and router.isActive
should match correctly an URL which has arrays in queryParams.
Minimal reproduction of the problem with instructions
Here is a plunker that show what the issue is: http://plnkr.co/edit/CgMuRGMvsu2KAOm0aYOQ
If you click on Link with an array in the plunker, the navigation is achieved, but the class active
is not added, and the link is not red. Because there is a queryParams with an array.
However, if you click on Link with an integer, it works fine, and the link is highlighted in red.
Identification of the issue
I have looked for the issue in angular code, and I think the issue is caused by this method which compare queryParams: In file packages/router/src/url_tree.ts:
function containsQueryParams(
container: {[k: string]: string}, containee: {[k: string]: string}): boolean {
return Object.keys(containee).length <= Object.keys(container).length &&
Object.keys(containee).every(key => containee[key] === container[key]);
}
The issue is that containee[key] === container[key]
cannot work with arrays.
[1] === [1]
is false
.
Maybe I can do a pull request to fix this.
What is the motivation / use case for changing the behavior?
I am using arrays in queryParams, to store some state in the URL, in order to be able to save the link and use it later. I could probably use a workaround ; sort and stringify my array before using it, but I prefer not to.
Environment
Angular version: 5.2.5
Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [x] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
I have fixed the issue with the PR #22666. kindly review @jasonaden
Any updates?