Skip to content

Commit

Permalink
Merge pull request emberjs#18458 from Alonski/bugfix/query-params-helper
Browse files Browse the repository at this point in the history
[BUGFIX] Using query params helper outside of link-to
  • Loading branch information
chancancode authored Oct 8, 2019
2 parents 414331d + c7404ca commit f786e42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
16 changes: 8 additions & 8 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,14 +838,14 @@ const LinkComponent = EmberComponent.extend({
)
);

if (DEBUG && this.query === UNDEFINED) {
let { _models: models } = this;
let lastModel = models.length > 0 && models[models.length - 1];

assert(
'The `(query-params)` helper can only be used when invoking the `{{link-to}}` component.',
!(lastModel && lastModel.isQueryParams)
);
let { _models: models } = this;
if (models.length > 0) {
let lastModel = models[models.length - 1];

if (typeof lastModel === 'object' && lastModel !== null && lastModel.isQueryParams) {
this.query = lastModel.values;
models.pop();
}
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ moduleFor(

this.addTemplate(
'index',
`{{#let (query-params foo='456' bar='NAW') as |qp|}}{{link-to 'Index' 'index' qp}}{{/let}}`
`{{#let (query-params foo='456' alon='BUKAI') as |qp|}}{{link-to 'Index' 'index' qp}}{{/let}}`
);

return assert.rejectsAssertion(
this.visit('/'),
/The `\(query-params\)` helper can only be used when invoking the `{{link-to}}` component\./
);
return this.visit('/').then(() => {
this.assertComponentElement(this.firstChild, {
tagName: 'a',
attrs: { href: '/?alon=BUKAI&foo=456', class: classMatcher('ember-view') },
content: 'Index',
});
});
}
}
);
Expand Down

0 comments on commit f786e42

Please sign in to comment.