Skip to content

Commit

Permalink
Merge pull request #396 from cah-briangantzler/fix-error
Browse files Browse the repository at this point in the history
Stop the error caused by routeWillChange
  • Loading branch information
NullVoxPopuli committed Nov 16, 2021
2 parents c1106ea + aae63eb commit fcc20a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions addon/services/query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { isPresent } from '@ember/utils';

import * as qs from 'qs';

import type Transition from '@ember/routing/-private/transition';
import type RouterService from '@ember/routing/router-service';

interface QueryParams {
Expand All @@ -29,8 +28,10 @@ export default class QueryParamsService extends Service {

// TODO: drop support for Ember < 3.24 and use @ember/destroyable
// to not cause a memory leak in tests
this.router.on('routeDidChange', () => this.updateParams());
this.router.on('routeWillChange', (transition) => this.updateURL(transition));
this.router.on('routeDidChange', () => {
this.updateParams();
this.updateURL(this.router.currentRouteName);
});
}

get pathParts() {
Expand Down Expand Up @@ -62,8 +63,8 @@ export default class QueryParamsService extends Service {
* throw them on the URL
*
*/
private updateURL(transition: Transition) {
const path = this.router.urlFor(transition.to.name);
private updateURL(routeName: string) {
const path = this.router.urlFor(routeName);
const { protocol, host, pathname, search, hash } = window.location;
const queryParams = this.byPath[path];
const existing = qs.parse(search.split('?')[1]);
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/application.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Controller from '@ember/controller';

export default class Application extends Controller {
queryParams = ['a', 'b', 'foo', 'bar'];
queryParams = ['a', 'b'];
}

0 comments on commit fcc20a6

Please sign in to comment.