Skip to content

Instantly share code, notes, and snippets.

@igbanam
Forked from danielchappell/route_hooks.js
Created October 9, 2017 14:53
Show Gist options
  • Save igbanam/f9719c3e49b36504df6871db20011d93 to your computer and use it in GitHub Desktop.
Save igbanam/f9719c3e49b36504df6871db20011d93 to your computer and use it in GitHub Desktop.
Ember.Route hook order
import Ember from 'ember';
// Ember 1.10
export default Ember.Route.extend({
//---fire in order on route enter---
beforeModel(transition) {
//empty by default
//Primarily for redirecting before the model is fetched
},
model(params, transition) {
//empty by default
// fetch the model from server here
// return a model
},
afterModel(model, transition) {
//empty by default
//accepts model for optional model setup
},
serialize(model, params) {
//has default behavior that serializes parameter out of passed model
//works perfectly if naming scheme is followed. More on this later.
//override to implement custom behavior
return {paramName: paramValue};
}
redirect(model, transition) {
//empty by default
// almost identical to afterModel
//but route is now considered active
},
activate() {
// empty by default
// used for optional setup after all model hooks
},
setupController(controller, model) {
//default implmentation sets model as property on controller
//must keep default behavior an optionally do more controller setup
controller.set('model', model);
},
renderTemplate(controller, model) {
//default implementation renders the template with the same name as the route
//with the default controller
// template name is passed as string
// override the function to customize which template and controller
// or to render mutiple templates
this.render(this.routeName, {
into: 'applcation',
controller: controller,
model: model
});
},
//----on route exit----
resetController(controller, isExiting, transition) {
//empty by default
//fires when route changes or model is refreshed
// isExiting property true when exiting (obviously)
},
deactivate() {
//empty by default
//fires on route exit
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment