From 6e99174bb69b4670f65a58cf8c436210d38ffebb Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Tue, 8 Oct 2019 08:43:09 +0200 Subject: [PATCH] Merge pull request #18458 from Alonski/bugfix/query-params-helper [BUGFIX] Using query params helper outside of link-to (cherry picked from commit f786e428c9a74daf5f17c06546f4baef4feb0af3) --- .../-internals/glimmer/lib/components/link-to.ts | 16 ++++++++-------- .../link-to/query-params-curly-test.js | 13 ++++++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/@ember/-internals/glimmer/lib/components/link-to.ts b/packages/@ember/-internals/glimmer/lib/components/link-to.ts index 710ce259959..e57bddd465b 100644 --- a/packages/@ember/-internals/glimmer/lib/components/link-to.ts +++ b/packages/@ember/-internals/glimmer/lib/components/link-to.ts @@ -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; diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-curly-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-curly-test.js index dd190616e22..3dd3bc7ec24 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-curly-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-curly-test.js @@ -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', + }); + }); } } );