Skip to content

Instantly share code, notes, and snippets.

@hjumeau
Last active January 14, 2016 16:52
Show Gist options
  • Save hjumeau/654a73ebda453aeab7c9 to your computer and use it in GitHub Desktop.
Save hjumeau/654a73ebda453aeab7c9 to your computer and use it in GitHub Desktop.
Redirecting
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{#link-to 'posts'}}posts{{/link-to}}
{{#link-to 'index'}}index{{/link-to}}
<br>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default Ember.Route.extend({
redirect(){
//this.transitionTo('posts');
},
beforeModel(){
Ember.Logger.info('index beforModel Hook');
},
model(){
Ember.Logger.info('index model Hook');
return 'Index Model';
},
afterModel(model, transition){
Ember.Logger.info('index afterModel Hook');
}
/*replace(){
this.transitionTo('posts');
}
*/
});
import Ember from 'ember';
export default Ember.Route.extend({
beforeModel(){
Ember.Logger.info('post beforeModel Hook');
},
model(params){
Ember.Logger.info('post model Hook');
return this.modelFor('posts')[params.post_id];
},
afterModel(model, transition){
Ember.Logger.info('post afterModel Hook');
}
});
<br>
Post
<br>
id : {{model.id}}
<br>
content: {{model.content}}
import Ember from 'ember';
export default Ember.Route.extend({
/*redirect(){
this.transitionTo('posts.post', {
id:1,
content: 'Ember is fast and furious'
});
},*/
beforeModel(){
Ember.Logger.info('posts beforeModel Hook');
//this.transitionTo('posts.post', {id: 1, content: 'Ember is fast and furious'});
},
model(){
Ember.Logger.info('posts model Hook');
return [{id: 0, content: 'Ember is awsome'},
{id: 1, content: 'Ember is fast and furious'}];
},
afterModel(model, transition){
Ember.Logger.info('posts afterModel Hook');
}
//this.transitionTo('posts.post', model.get('lastObject'));
});
Posts content
{{outlet}}
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('posts', function() {
this.route('post', { path: ':post_id' });
});
});
export default Router;
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment