Open fastfedora opened 2 years ago
Thanks for filing this!
This could be implemented directly within Ember with little disruption, since it's unlikely existing code is passing an empty hash into
@query
.
You might be surprised. π Suffice it to say that in the current state of the router, basically any change breaks something, and with enough users nearly any behavior you can think of does actually occur in the wild. An example of how this one could come up pretty easily:
import class Component from '@glimmer/component';
export default class Example extends Component {
get queryParams() {
// construct a QP object... which might be empty!
}
}
<LinkTo @route='some.route' @query={{this.queryParams}}>Whoops!</LinkTo>
Weβre working on improving/fixing the router situation, though!
Just want to +1 on this. :)
Same here +1;
+1
Just ran into this issue as well. There is really no easy way to remove query params upon entering the route if they are invalid.
π Describe the Bug
Ember uses sticky query parameters by default. To make a parameter non-sticky, the documentation says there are two options:
<LinkTo />
ortransitionTo
.Route.resetController
hook to set query param values back to their defaults before exiting the route or changing the route's model.However, when transitioning to the same page, both options must be used. It is not sufficient to merely reset the query parameters in
Route.resetController
.More specifically, there is no way to reset all parameters when transitioning to a route, as
Route.resetController
only resets the parameters when transitioning from a route.Explicitly passing in default values in
<LinkTo />
ortransitionTo
will work, but is fragile, as it relies on the caller knowing what query parameters have been defined on the route.π¬ Minimal Reproduction
See this Ember Twiddle for an example.
This is a simplified example of an issue we're having in our current application. The links are contained within a navigation menu, so shouldn't have any knowledge of the implementation of the profile page. However, the only link that works is when the navigation menu knows exactly what query parameters have been defined for the route.
π Actual Behavior
Query parameters are sticky, even if you attempt to make them non-sticky using
Route.resetController
, when transitioning to the same page.π€ Expected Behavior
There should be a way to specify query parameters as non-sticky so that links to a route don't require knowledge of what query parameters have been defined on that route to get a default view.
Ideally there would be a way to turn off sticky behavior by default for query parameters, either at the route level or for the entire application. For links, there should be a way to request a route without existing parameter values being copied into the request.
π Environment
β Additional Context
This is similar to issue #10260.
One workaround is to override the router service so that when an explicitly empty
queryParams
object is passed to initiate a transition, existing query parameters are not copied to theto
transition:With this change,
<LinkTo @route="my-route" @query={{hash}}>
would reset the query parameters, while<LinkTo @route="my-route">
would not.This could be implemented directly within Ember with little disruption, since it's unlikely existing code is passing an empty hash into
@query
.