I am trying to understand the setupController
and model
hooks, will they be invoked only in case of dynamic segments?
This is my router configuration, I see the application is working fine,but I do not see these hooks getting executed:
// Router, this need to connect view and controller
App.Router.map(function(){
this.resource("login", {path : "/"});
this.resource("home" , {path : "home/:home_id"});
});
App.Router.IndexRoute = Ember.Route.extend({
setupController:function(controller,model){
console.log("in setupController hook for index route");
}
});
App.Router.LoginRoute = Ember.Route.extend({
setupController:function(controller,model){
console.log("in setupController hook for login route");
}
});
App.Router.HomeRoute = Ember.Route.extend({
setupController:function(controller,model){
console.log("in setupController hook for login route");
}
});
Assuming you are using the latest ember (1.0.0-RC.1) You should define your routes like this:
App.HomeRoute = Ember.Route.extend({
...
});
They are part of your App
, and don't have the Router
part.
Working JSBin example
As a note on model
and setupController
hook behavior:
In a route, model
will only be called when navigating directly to a URL containing a dynamic segment. The parameters passed into model
are used to retrieve the model for that route using the dynamic segment.
If the route is reached using a {{#linkTo route myObject}}
or transitionTo(myObject)
call then the passed object is used to call setupController
directly and model
is not called.
The setupController
hook will be called every time the route enters the
Ember API docs for model
Ember API docs for setupController
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With