Skip to content

Instantly share code, notes, and snippets.

@feanor07
Created April 13, 2017 12:31
Show Gist options
  • Save feanor07/e1d428a233644499e3dcbba92d7f81a2 to your computer and use it in GitHub Desktop.
Save feanor07/e1d428a233644499e3dcbba92d7f81a2 to your computer and use it in GitHub Desktop.
so#43387430
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
category: 'my-category',
location: Ember.computed.oneWay('router.location.path'),
actions: {
makeTransition() {
let category = this.get('category');
this.transitionToRoute('my-route');
}
}
});
// app/initializers/component-router-injector.js
export function initialize(application) {
// Injects all Ember components with a router object:
application.inject('controller', 'router', 'router:main');
}
export default {
name: 'router-injector',
initialize: initialize
};
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('my-route');
this.route('dynamic-route', { path: '/dynamic-route/:id' });
this.route('other-route');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
category: {
refreshModel: true
}
},
model(params) {
let category = params.category || "NaN";
return category + "" + Math.random();
}
});
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
category: {
refreshModel: true
}
},
model(params) {
let category = params.category || "NaN";
return category + "" + Math.random();
},
serializeQueryParam() {
this._super(...arguments);
}
});
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
a: {
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
{{input value=category}}
<button {{action 'makeTransition'}}>Transition to</button>
<br>
{{#link-to "dynamic-route" 1 (query-params category="your-category")}}To dynamic route with static param{{/link-to}}
{{outlet}}
<br>
{{#link-to "my-route" (query-params category=category)}}To my route with controller param{{/link-to}}
<br>
{{#link-to "my-route"}}To my route without param{{/link-to}}
<br>
{{#link-to "my-route" (query-params category="your-category/2")}}To my route with static param{{/link-to}}
<br>
{{#link-to "dynamic-route" 1 (query-params category=category)}}To dynamic route with controller param{{/link-to}}
<br>
{{#link-to "dynamic-route" 1 (query-params)}}To dynamic route without param{{/link-to}}
<br>
{{#link-to "other-route" (query-params a=undefined)}}To other route without param{{/link-to}}
<br>
{{#link-to "other-route" (query-params a='2')}}To other route with param{{/link-to}}
<br>
{{location}}
@dynamic-route
<br>
category is : {{model}}
@my-route
<br>
category is : {{model}}
{
"version": "0.10.7",
"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.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment