Skip to content

Instantly share code, notes, and snippets.

@tobymarsden
Last active October 18, 2017 18:25
Show Gist options
  • Save tobymarsden/91e7b67f87afc0836c4f to your computer and use it in GitHub Desktop.
Save tobymarsden/91e7b67f87afc0836c4f to your computer and use it in GitHub Desktop.
Working sticky params
import Ember from 'ember';
export default Ember.Route.extend({
beforeModel: function() {
this.transitionTo('parent', 'A');
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['test'],
test: 1,
actions: {
update: function() {
this.incrementProperty('test');
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params) {
return new Ember.RSVP.Promise(function(resolve) {
setTimeout(function() {
resolve({name: 'A'});
}, 500);
});
}
});
<h3>Query param value: {{test}}</h3>
<button {{action 'update'}}>Click me to change the query param value!</button>
<p>{{#link-to 'parent.index' 'B' }}Then change the model param{{/link-to}}</p>
<p>... click the button a few more times...</p>
<p>{{#link-to 'parent.index' 'A' }}Return to the first model param again{{/link-to}} and see that the query param value is sticky.</p>
<p>{{#link-to 'parent.index' 'B' }}And back to the second model param again{{/link-to}} to confirm it.</p>
{{outlet}}
import Ember from 'ember';
import config from './config/environment';
var Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('parent', {path: '/:parent_param'}, function() {});
});
export default Router;
{
"version": "0.4.16",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.1.0",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js",
"ember-template-compiler": "2.1.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment