Skip to content

Query params containing commas result in an extra navigation #16067

Closed

Description

@bourey

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
When visiting an ng2 URL with a query parameter value containing a comma, ng2 redirects to the same path with all query parameters removed.

Expected behavior
Parameters should not disappear, and the router should properly report the value for the query param.

Minimal reproduction of the problem with instructions
Steps to reproduce:

  1. Download https://github.com/bourey/ngupgrade-example/tree/ng2
  2. npm start
  3. npm install
  4. Visit http://localhost:3000/teams?foo=bar,baz

What is the motivation / use case for changing the behavior?
Our product currently has some parameter values containing commas, and we need to support them.

Please tell us about your environment:

  • Angular version: 4.0.2
  • Browser: Chrome
  • Language: TS

Activity

  1. changed the title [-]Query params containing commas result in a redirect[/-] [+]Query params containing commas result in an extra navigation[/+] on Apr 17, 2017
  2. self-assigned this
    on Apr 18, 2017
  3. vicb commented on Apr 21, 2017

    @vicb
    Contributor

    The first navigation is triggered by the Angular2 router

    Subsequent navigations are initiated by the interop, most specifically:

    function setUpLocationSync(ngUpgrade) {
        if (!ngUpgrade.$injector) {
            throw new Error("\n        RouterUpgradeInitializer can be used only after UpgradeModule.bootstrap has been called.\n        Remove RouterUpgradeInitializer and call setUpLocationSync after UpgradeModule.bootstrap.\n      ");
        }
        var router = ngUpgrade.injector.get(_angular_router.Router);
        var url = document.createElement('a');
        ngUpgrade.$injector.get('$rootScope')
            .$on('$locationChangeStart', function (_, next, __) {
            url.href = next;
            router.navigateByUrl(url.pathname);
        });
    }

    from the router-upgrade

  4. vicb commented on Apr 21, 2017

    @vicb
    Contributor

    Seems like changing router.navigateByUrl(url.pathname); for router.navigateByUrl(url.pathname + url.search); fixes the issue

  5. added a commit that references this issue on Apr 21, 2017
    618e6ad
  6. added a commit that references this issue on May 2, 2017
    ccc81cc
  7. bourey commented on May 24, 2017

    @bourey
    Author

    While query parameters aren't dropped anymore, it looks like they're still not being handled properly. Now I see a brief flicker in the location bar, which appears to correspond to the URL quickly changing to http://localhost:3000/teams?foo=bar2%2baz, then back to http://localhost:3000/teams?foo=bar,baz.

    The browser's back button also doesn't successfully navigate back in the URL history for parameters containing a comma. To demonstrate this, try the original repro case, but add queryParamsHandling="merge" to the link in team_list.component.html. If you click on a team link, then attempt to use the browser's "back" functionality, the page is not updated.

  8. naomiblack commented on May 24, 2017

    @naomiblack
    Contributor

    re-opening this one. @vicb @mhevery @jasonaden

  9. KKrisu commented on Jun 20, 2017

    @KKrisu

    One addition from me: The setUpLocationSync function has another issue - it drops the hash part of the url.
    So the fix probably should be router.navigateByUrl(url.pathname + url.search + url.hash);

    cc @vicb @mhevery @jasonaden @naomiblack

  10. jasonaden commented on Jun 29, 2017

    @jasonaden
    Contributor

    @KKrisu Yes, looks like you're correct. I'll add that in as well.

  11. 2 remaining items

  12. added 4 commits that reference this issue on Jul 7, 2017
    7f5eb61
    8f7cce3
    9c3217d
  13. added 2 commits that reference this issue on Aug 11, 2017
    b01f4b9
    7c420f8
  14. added 2 commits that reference this issue on Aug 28, 2017
    73978ef
    8c1842d
  15. angular-automatic-lock-bot commented on Sep 12, 2019

    @angular-automatic-lock-bot

    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.

  16. locked and limited conversation to collaborators on Sep 12, 2019
  17. added a commit that references this issue on Nov 20, 2026
    fbfb7df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions