Skip to content

Instantly share code, notes, and snippets.

@foxnewsnetwork
Last active May 7, 2018 17:07
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 foxnewsnetwork/35d17365268a18eea4d3c64ba00ce79a to your computer and use it in GitHub Desktop.
Save foxnewsnetwork/35d17365268a18eea4d3c64ba00ce79a to your computer and use it in GitHub Desktop.
QueryParams Demo
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'QueryParams Demo',
referrerLocation: null,
queryParams: ['referrerLocation']
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('home', { path: '/' });
this.route('product', { path: 'product/:productId' });
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
referrerLocation: {
replace: true,
refreshModel: false
}
}
});
import Ember from 'ember';
export const FRUITS = {
apple: 'https://cdn.iconscout.com/public/images/icon/free/png-256/apple-fruit-food-vitamin-healthy-30aba8081bb38594-256x256.png',
orange: 'https://cdn1.iconfinder.com/data/icons/fruits-vegetables-16/512/22_Citrus_food_fruit_orange-256.png',
banana: 'https://images.vexels.com/media/users/3/143061/isolated/lists/aaf71ed4e387a6838e1c521fbecde77a-banana-icon-fruit.png'
};
export default Ember.Route.extend({
model() {
return FRUITS;
}
});
import Ember from 'ember';
import { FRUITS } from './home';
export default Ember.Route.extend({
model({ productId }) {
return FRUITS[productId];
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.lolog img {
width: 125px;
border: 3px dotted blue;
}
<h1>Welcome to {{appName}} - referrerLocation: {{referrerLocation}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<h3>References</h3>
<ul>
<li>
<a href='https://emberjs.com/api/ember/3.1/functions/@ember%2Fcontroller/inject'>
controller injects only works in controllers
</a>
</li>
<li>
<a href='https://github.com/offirgolan/ember-parachute'>
ember parachute (community addon for less bad qp handling)
</a>
</li>
</ul>
<h2>List of List of Fruits</h2>
<p>
The point of this twiddle is to demostrate that you <strong>need</strong> to specify query-params on all links if you specify it on one link
</p>
<h3>
Common Fruits
</h3>
<div class='lolog'>
{{#each-in model as |key src|}}
{{#link-to 'product' key (query-params referrerLocation=key)}}
<img src={{src}}>
{{/link-to}}
{{/each-in}}
</div>
<h2>Fruit Details</h2>
<img src={{model}}>
<ul>
<li>
{{#link-to 'home'}}
Home without referrerLocation
{{/link-to}}
</li>
<li>
{{#link-to 'home' (query-params referrerLocation='product')}}
Home with referrerLocation
{{/link-to}}
</li>
</ul>
{
"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