How can I reset sticky query params?


#1

This question is asked very frequently in Slack #-help, so I thought I would add it here.


#2

Currently the best, addon-free method is to use the resetController hook in the route. There’s more on this in the guide plus example code, but it’s often missed: https://guides.emberjs.com/v3.0.0/routing/query-params/#toc_sticky-query-param-values.

For more complex use-cases, you may want to try using https://github.com/offirgolan/ember-parachute.

Example code in case that link becomes unreachable:

import Route from '@ember/routing/route';

export default Route.extend({
  resetController(controller, isExiting, transition) {
    if (isExiting) {
      // isExiting would be false if only the route's model was changing
      controller.set('page', 1);
    }
  }
});