You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow global configuration of queryParamsHandling #16558
[ ] 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 =
Reacted by louis, Trung Vo, Fabian Dietenberger, SquadWuschel, Gady, Jeric de Leon and Andrey Kolkov
@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"?
@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.
@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).
Activity
vicb commentedon May 5, 2017
@voithos Being able to set a global default that you can override on
routerLink/Routersounds reasonable, would it solve all your use case ?IMO a global
QueryParamsHandlingStrategywould be overkill and hard to keep in sync with the individual routes/params.voithos commentedon May 5, 2017
@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 differentqueryParamsHandling, 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 ownQueryParamsHandlingmethod).What do you mean by
QueryParamsHandlingStrategybeing "hard to keep in sync with the individual routes/params"?jasonaden commentedon May 10, 2017
@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.voithos commentedon May 12, 2017
@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
QUeryParamsHandlingStrategyinterface - both should work fine, I imagine).jasonaden commentedon May 31, 2017
Closing this issue as the feature will not be added at this time. See #16998 for more details.
angular-automatic-lock-bot commentedon Sep 11, 2019
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.