Skip to content

Instantly share code, notes, and snippets.

@bendemboski
Last active May 8, 2020 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendemboski/10945d792140b965a2876f4f98bc3d13 to your computer and use it in GitHub Desktop.
Save bendemboski/10945d792140b965a2876f4f98bc3d13 to your computer and use it in GitHub Desktop.
Query Params Bug
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking'
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class MyRouteController extends Controller {
queryParams = [ { detailId: 'detail' } ]
@tracked detail
@service('router') router
@action
async doTransition() {
this.router.transitionTo('index');
this.router.transitionTo('my-route', { queryParams: { detail: this.detailId } });
}
}
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('my-route');
});
export default Router;
import Route from '@ember/routing/route';
export default Route.extend({
redirect() {
this.transitionTo('my-route', { queryParams: { detail: 1 } });
}
});
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<p>
This route accepts the `detail` query param.
</p>
<p>
Clicking this button will tell the router service to transition to '/'
and then without waiting for it to complete, will tell it to transition
back to this route, specifying a value for the `detail` query param.
If you watch the console, you'll see an error throws from within the
router service that looks like this:
</p>
<pre style="color: red">
VM58 about:srcdoc:74 Uncaught (in promise) Error: Assertion Failed: You passed the `my-route:detailId` query parameter during a transition into my-route, please update to detail
at assert (ember.debug.js:35787)
at Class._hydrateUnsuppliedQueryParams (ember.debug.js:23017)
at Class._prepareQueryParams (ember.debug.js:22841)
at Class._doTransition (ember.debug.js:22789)
at RouterService.transitionTo (ember.debug.js:18623)
at MyRouteController.doTransition (VM58 about:srcdoc:69)
</pre>
<button type="button" {{on "click" this.doTransition}}>click me</button>
{
"version": "0.17.0",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.17.0",
"ember-template-compiler": "3.17.0",
"ember-testing": "3.17.0"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment