Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Query Params Not Updating With Refresh
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
import Controller from '@ember/controller';
export default Controller.extend({
actions: {
addQP() {
return true;
},
refresh() {
return true;
}
}
});
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', { path: '/' });
});
export default Router;
import Route from '@ember/routing/route';
export default Route.extend({
queryParams: {
foo: { refreshModel: true }
},
model(params, transition) {
let foo = transition.to.queryParams.foo || 'no QPs exist';
console.log(`Query Params: ${transition.to.queryParams}`);
return { foo };
},
actions: {
addQP() {
console.log('updating params');
this.set('controller.foo', 'bar');
//this.refresh();
},
refresh() {
console.log('updating params and refreshing');
this.set('controller.foo', 'stuff');
this.refresh();
}
}
});
<h1>Welcome to {{this.appName}}</h1>
<br>
<p>This demo renders the query param "foo" to the template if it exists, otherwise it says "no QPs exist".</p>
<p>Click the "Add a QP" button to see the value get updated and the model refreshed. Click the "add a QP and refresh" button to see the value get updated without the model receiving the correct query param upon refresh. In particular, this should work when `refreshModel` is set to false, allowing you to programmatically refresh the model using refresh() only when needed instead of every time the query param is updated.</p>
<br>
{{outlet}}
<br>
<br>
<button {{action 'addQP'}}>Add a QP</button>
<button {{action 'refresh'}}>Add a QP and refresh</button>
<p>{{model.foo}}</p>
{
"version": "0.17.1",
"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.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.