Skip to content

Instantly share code, notes, and snippets.

@armiiller
Forked from Andrew-Max/gist:305483febc3c367dbf57
Last active November 10, 2017 16:45
Show Gist options
  • Save armiiller/27d944a6b11c6e707ac36e9aa8e97591 to your computer and use it in GitHub Desktop.
Save armiiller/27d944a6b11c6e707ac36e9aa8e97591 to your computer and use it in GitHub Desktop.
Route lifecycle hooks guide from Ember meetup lightning talk
// https://www.emberjs.com/api/ember/2.15/classes/Ember.Route
App.LibraryRoute = App.ApplicationRoute.extend({
activate: function () {
//no longer enter
this._super();
only called once on entering a route.
},
beforeModel: function (transition) {
// any state you want in place before the model is initialized, this is called before any model promises are resolved
// also could be used to conditionally prevent access to a route by throwing transition.abort
},
model: function (params, transition) {
// interesting note, if you tranisition into a route via a dynamic route segment this will never
// not get called because the model will have already been specified ie {{#link-to 'article' article}}
// in that case use beforeModel or afterModel
},
// https://www.emberjs.com/api/ember/2.15/classes/Ember.Route/methods/beforeModel
afterModel: function (model, transition) {
//anything that may need to reference a model
},
serialize: function (model, params) {
// setup any dynamic routes
},
setupController: function (controller, model) {
// set additional properties on the controller, or override it’s content.
},
renderTemplate: function (controller, model) {
// can be useful for setting up third party libraries. with a call to this._super
//also could be used to setup a non-default template without super
},
deactivate: function (/* no params 8?) {
this._super();
//no longer exit
}
actions: {
willTransition: function () {
//can be used to prevent a transition on make sure some state is ready for the next route
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment