Skip to content

route redirectTo not preserving query params #13315

Closed

Description

@mdsauer

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
Prior to release 2.3 query parameters were preserved through a configured route redirectTo. This is no longer working in 2.3. Is this an expected breaking change or was the prior behavior not correct?

Expected behavior
Query params preserved on a redirectTo, or at least allow it to be configured to do so.

Minimal reproduction of the problem with instructions
{ path: '',
redirectTo: '/component1',
pathMatch: 'full'
},
{ path: 'component1',
component: Component1
},

In Component1:
ngOnInit(): void {
let params = this.route.snapshot.queryParams; //route is ActivatedRoute

Prior to 2.3 params passed in url as /?param1=val1&param2=val2 would be available to Component1

Please tell us about your environment:
Windows 7, VS Code

  • Angular version: 2.3

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
    Chrome, IE11

Activity

  1. DzmitryShylovich commented on Dec 8, 2016

    @DzmitryShylovich
    Contributor

    Pls add a repro in plunkr.

  2. added
    needs reproduction
    on Dec 8, 2016
  3. zoechi commented on Dec 9, 2016

    @zoechi
    Contributor

    dup of #12664 ?

  4. DzmitryShylovich commented on Dec 9, 2016

    @DzmitryShylovich
    Contributor

    don't think so. According to:

    Prior to release 2.3 query parameters were preserved through a configured route redirectTo. This is no longer working in 2.3

    it's a regression.

  5. mdsauer commented on Dec 9, 2016

    @mdsauer
    Author

    @DzmitryShylovich I would be happy to create a repro but I am not familiar with creating a repro in plnkr. I did see in another issue the following:
    u can use http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5 as a starting point
    But it is not clear to me how I specify the version of angular to run under. Can you point me to some instructions?

  6. DzmitryShylovich commented on Dec 9, 2016

    @DzmitryShylovich
    Contributor

    But it is not clear to me how I specify the version of angular to run under. Can you point me to some instructions?

    u don't need to specify anything. the plunkr already uses the latest version.

  7. mdsauer commented on Dec 9, 2016

    @mdsauer
    Author

    repro: http://plnkr.co/edit/EmmObNPt7lofzoM9YozT?p=preview

    Result I get with this code running against 2.2.0 is:
    Test Router Query Params
    queryParams: params: {"param1":"val1","param2":"val2"}
    routeData: params: {"param1":"val1","param2":"val2"}

    I should add that I am not sure how to pass the query params into the plnnkr.
    My bs-config.json has: "startPath": "/?param1=val1&param2=val2"

    @DzmitryShylovich what is the expected behavior for query params with redirects? I could not find any clear documentation. If what I was attempting is not really supposed to be supported I will change my code. Thanks.

  8. mdsauer commented on Dec 13, 2016

    @mdsauer
    Author

    I changed my redirect from an absolute to a local and now the query params are retained. I think this issue can be closed.

  9. DzmitryShylovich commented on Dec 13, 2016

    @DzmitryShylovich
    Contributor

    @mdsauer u can close it yourself

  10. SusanAWAL commented on Apr 11, 2018

    @SusanAWAL

    @mdsauer can you put youe solution here, please?

  11. veroca commented on Oct 5, 2018

    @veroca

    @SusanAWAL a little late I guess, but I'll leave the comment here for future visitors.
    To conserve the query params, instead of:

      { 
        path: 'whatever',
        redirectTo: '/component1'
      },
    

    do:

      { 
        path: 'whatever',
        redirectTo: 'component1'
      },
    
  12. Ruluk commented on Dec 28, 2018

    @Ruluk

    I don't think this is ideal or logical. I don't see any reason why absolute paths shouldn't forward query params. At the very least, there should be a property to configure this.

  13. MaverickH commented on Jan 23, 2019

    @MaverickH

    The #1 reason to want to preserve those query params would be url re-writes where it is reasonable to assume the original url may be bookmarked by a user.

  14. angular-automatic-lock-bot commented on Sep 14, 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.

  15. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerneeds reproduction

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions