Model hook does not get called for nested routes


I am using ember-cli v 0.2.1. My router.js looks as follows: {
  this.route('projects', function() {
    this.route('project-id', { path:':id' });

My routes/projects.js looks as follows:

export default Ember.Route.extend({
  model: function(){
    var clientID = 'FooBarFooBarFooBar';
    var query = 'motorcycle';
    var url = ""+ query +"&client_id="+ clientID;
    return ajax({url:url,type:'GET', dataType: "jsonp"}).then(function(res){	
      return res.projects;

Part of my templates/projects.hbs looks as follows:

{{#each item in content}}
<div class="row">
   {{#link-to 'projects.project-id' item}}

My routes/projects/project-id.js looks as follows:

export default Ember.Route.extend({
	model: function(parmas){
	  var clientID = 'FooBarFooBar';
	  var url = ""+ +"?api_key="+ clientID;
	  return ajax({url:url, type:'GET', dataType: "jsonp"}).then(function(res){	
	    return res.project;

When I click on a particular project, URL changes with appropriate project id but model hook in project-id.js does not get called. It gets called when I refresh the page with URL /projects/:project_id already set in it. Please, help me understand this behaviour. I want the model hook to be called when someone clicks on the particular project.


I have observed that setupController hook is called when you transition inside app and model and setupController hooks are called in order when you reload the route url. Try implementing setupController method and debug it both ways.

{{#link-to 'projects.project-id' item}}

You could force the model hook call by changing the line above to

{{#link-to 'projects.project-id'}}


Passing calls the model hook which satisfies the purpose for now. Thanks for the help.


The behaviour you’re seeing is accused by the fact, that the beforeModel and model hooks are not invoked if you’re passing an object within the {{link-to}} helper. If you pass an object, this object will be treated like the already resolved model which causes Ember to bypass the all hooks before afterModel.


Yes, you are right. setupController hook gets invoked as well. Thanks.


@herom @splattne @kushdilip I understand the behavior now. If I pass a string ( inside {{link-to}} helper, model and beforeModel hook gets invoked, but if I pass an object (item) model and beforeModel hook does not get invoked. And setupController hook always gets invoked. Thanks.


I also ran into this but found that when I link-to or transitionTo a parent route (with no params) I needed to tell the router w/ a query string to always refresh. If anyone is interested in how I did this - this commit shows all the changes required to force my top level model hook to fire any time you link-to or transitionTo it