-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE query-params] Removing query-params from links explicitly? #5274
Comments
Having written all this down, one way of solving this is to create a controller action that resets the query param properties. Still, there might be use cases for resetting query params from within a |
@lfridael The query-params logic stores and compares the provided value against the original value. If you set e.g.
|
@bradleypriest Thx! That was the hint I needed. However, using I.e.
UPDATE. Just to be clear: using an empty string as the default property value removes the query params from the |
@lfridael I think the issue is documentation; I believe your use case would be handled by using the new See here for an example https://github.com/emberjs/ember.js/blob/master/packages/ember/tests/routing/query_params_test.js#L1375-L1382 Let me know if this addresses your use case (I'm doing a ton of QP work now, including documentation, so I'll make sure this is more clear) |
Closing for now given that setting to default property in the link-to is working for you. At some point in the future we might add some more API but that would best start in a discuss.emberjs.com thread rather than GH issues. |
@machty Just experimented with the Anyway, the current API is fine, with the only minor consequence being that links might have to be aware of QP defaults. In practice, I don't see this becoming much of a problem. A global link in a navbar such as |
We may add something like a |
I had the same problem as @lfridael and was able to solve it by using
It seems that the difference is between using So, setting |
This is something that should have been resolved a long time ago. Ember should give the tools to do all things a user expects to happen. When I am on github issues here and filter With ember you can't do that in a "proper" way. We either have either use a custom I don't even understand any reason to use stick query params. They have caused me issues since day 1 and I haven't seen any benefits other than pagination links (which are part of the route I am in so could easily get the same benefit in other ways without ruining every link to the page). I am just going to have to create the |
So other people can solve this in a hackyish way that is actually maintainable (still need to do the Added a helper to use called import Ember from 'ember';
export function explicitQueryParams(params, hash) {
let values = Ember.assign({}, hash);
values._explicitQueryParams = true;
return Ember.Object.create({
isQueryParams: true,
values: values,
});
}
export default Ember.Helper.helper(explicitQueryParams); This is pretty much the same as the default (can be empty though) but we set a param we can check in the router (the hackyish part). If I turn this into an addon I will also make this helper wotk better than the super restrictive Then in your _hydrateUnsuppliedQueryParams(state, queryParams) {
if (queryParams._explicitQueryParams) {
delete queryParams._explicitQueryParams;
return queryParams;
}
return this._super(state, queryParams);
}, This isn't the cleanest way but the "proper" way would also involve replacing the |
I'm new to ember and am struggling with this too. I wrote a post about it on ember discussion forum: The more time I spend on it, the more I think that you have to roll your own "parameter manager" (but I still could be missing tools that may already exist). Right now when an action is triggered I'm just analyzing what params are on the url, passing them thru my custom ruleset, and outputting an entirely new url (in the route). Which makes me think I am doing things the jquery way and not the ember way. I think it would be great if there were a built-in tools to help do this. I have no idea what they'd look like tho! |
thx @robclancy,
then all link-to sticky query params is disabled by default, and we can enable it by adding QP like:
|
My way no longer works because of an ember update. I am now overriding helpers/query-params.js import { helper } from '@ember/component/helper';
class QueryParams {
values = null;
isQueryParams = true;
constructor(values = null) {
this.values = Object.assign({ ['-sticky']: false, values });
}
}
export default helper(function queryParams(_, params) {
return new QueryParams(Object.assign({}, params));
}); router.js extending _hydrateUnsuppliedQueryParams(state, queryParams) {
let sticky = queryParams['-sticky'] !== false;
delete queryParams['-sticky'];
return sticky ? this._super(state, queryParams) : queryParams;
}, |
Good work on the query-params in the 1.7 beta. It works well for my app, except for one thing that I can't figure out.
Once a query-param is set through a link...
...links to the same "bare" route (without query-params) now have the query params appended automatically.
I.e.
now results in a route hash
#/myroute?filter=123
. OK, great.Now my question: how do I generate query-paramless URLs once a param has been set in an earlier transition?
I tried:
but that leads to
#/myroute?filter=undefined
Of course I can work around it like this:
but I'd prefer a clean URL.
BTW, I tried both the hash and history-based routing strategies.
Summarizing: is there a way to clear query-params explicitly through a
link-to
helper? Or would this not be the framework-prescribed way of solving the problem?The text was updated successfully, but these errors were encountered: