Skip to content

Allow global configuration of queryParamsHandling #16558

Closed

Description

@voithos

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

[ ] bug report => search github for a similar issue or PR before submitting
[x] 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
Currently, when using routerLink or the router directly, we can specify queryParamsHandling in the template/call to control the query params propagation behavior. Unfortunately, if we want to propagate certain query params throughout the entire site, this becomes cumbersome and error prone (requiring adding it to every single routerLink that we use).

Expected behavior
It would be useful if there was a mechanism to configure queryParamsHandling in a global way, either by changing the "default" or, more ideally, if there was something akin to UrlHandlingStrategy (maybe call it QueryParamsHandlingStrategy?) that would allow us to configure how certain (but not all) query params are handled, without having to repeatedly do so for every routerLink usage.

What is the motivation / use case for changing the behavior?
tl;dr - Use case is to configure queryParamsHandling in a centralized place for the entire app, and allow configuring different strategies for different query params.

Please tell us about your environment:

  • Angular version: 4.0.X

  • Browser: all

  • Language: all

  • Node (for AoT issues): node --version =

Activity

  1. vicb commented on May 5, 2017

    @vicb
    Contributor

    @voithos Being able to set a global default that you can override on routerLink / Router sounds reasonable, would it solve all your use case ?

    IMO a global QueryParamsHandlingStrategy would be overkill and hard to keep in sync with the individual routes/params.

  2. voithos commented on May 5, 2017

    @voithos
    ContributorAuthor

    @vicb A global default would be useful, but I think it wouldn't handle the case where a page uses a query parameter for some non-global state - in the example of queryParamsHandling="merge", every outgoing link from said page would need to explicitly set a different queryParamsHandling, as well as explicitly filter the params that it propagates. Of course, you could argue that such state shouldn't be in the query params at all, but it just seems like something like a handling strategy would allow us to be more fine grained and less brittle with how the merging works (essentially defining our own QueryParamsHandling method).

    What do you mean by QueryParamsHandlingStrategy being "hard to keep in sync with the individual routes/params"?

  3. jasonaden commented on May 10, 2017

    @jasonaden
    Contributor

    @voithos That makes sense. So how about we add a way to globally configure queryParamsHandling, as well as configure by route? That way you can override at any level.

    We can also add an option to provide a function to fully customize the strategy. Something like (current: Params, future: Params) => Params.

  4. voithos commented on May 12, 2017

    @voithos
    ContributorAuthor

    @jasonaden Yeah, that seems like it'll work - allowing a function that can fully customize the strategy was pretty much what I had in mind (whether that takes the form of a free-form function, or some kind of QUeryParamsHandlingStrategy interface - both should work fine, I imagine).

  5. jasonaden commented on May 31, 2017

    @jasonaden
    Contributor

    Closing this issue as the feature will not be added at this time. See #16998 for more details.

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

  7. locked and limited conversation to collaborators on Sep 11, 2019
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