Skip to content

Instantly share code, notes, and snippets.

@chvonrohr
Last active May 10, 2018 00:33
Show Gist options
  • Save chvonrohr/27a8510061ddeeda802895197db63844 to your computer and use it in GitHub Desktop.
Save chvonrohr/27a8510061ddeeda802895197db63844 to your computer and use it in GitHub Desktop.
QueryParamExample
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['search'],
search: '',
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'QueryParam override Test'
});
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['search'],
search: '',
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('address');
this.route('project');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
myDefaultParam: 'address-1234',
firstLoad: true,
queryParams: {
search: { refreshModel: true },
},
beforeModel(transition) {
if (this.get('firstLoad')) {
let queryParams = { search: this.get('myDefaultParam') };
this.replaceWith(this.routeName, { queryParams: queryParams });
this.set('firstLoad', false);
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
myDefaultParam: 'project-5678',
firstLoad: true,
queryParams: {
search: { refreshModel: true },
},
beforeModel(transition) {
if (this.get('firstLoad')) {
let queryParams = { search: this.get('myDefaultParam') };
this.replaceWith(this.routeName, { queryParams: queryParams });
this.set('firstLoad', false);
}
}
});
Search Address: {{search}}
<h1>Welcome to {{appName}}</h1>
<br>
{{#link-to 'application'}}Main{{/link-to}} |
{{#link-to 'address'}}Address{{/link-to}} |
{{#link-to 'project'}}Project{{/link-to}}
<br>
<br>
{{outlet}}
<br>
<br>
Search Project: {{search}}
{
"version": "0.13.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment