I am working on a basic ember.js application and am a bit confused about some behavior. I have several routes that look like this:
this.resource('campaigns', { path: '/campaigns'}, function() { this.route('new', { path: '/new' }); this.route('campaign', { path: '/:campaign_id' }); }); App.CampaignsIndexRoute = Ember.Route.extend({ model: function() { App.Keyword.find(); return App.Campaign.find(); }, renderTemplate: function(controller, model) { this.render({outlet: 'page'}); } }); App.CampaignsCampaignRoute = Ember.Route.extend({ model: function(params) { alert("Model Firing"); console.log(params.campaign_id); return App.Campaign.find(params.campaign_id); }, renderTemplate: function(controller, model) { this.render({outlet: 'page'}); alert("Template Firing"); }
});
... and a view that looks like this:
App.CampaignsCampaignView = Em.View.extend({ templateName: 'templates/campaigns/campaign', });
... and a basic template that looks like this:
{{ view App.HeaderView }} <div id="app" class=""> <div id="sidebar"> {{ view App.NavigationView }} {{ view App.StarredCampaignsView }} </div> <div id="stage" class=""> <div id="stage-sidebar" class=""> {{ view App.StageSidebarView }} </div> <div id="page" class=""> {{ outlet page }} </div> </div> </div>
As you can see, there are two very simple warnings in the CampaignsCampaign route to let me know what is being activated.
So, / # / campaign returns a list of campaigns, / # / campaign / new returns a creation page and / # / campaign /: campaign_id should display one campaign and its details.
All this works great inside the system. When you click a campaign in the / # / campaign view, it directly links to the detailed view with all the necessary information loading.
Problem
The problem arises if you just type something like http://mysite.com/#/campaigns/ANY_ID and donβt click the link from the list. just loads empty, and renderTemplate is not called (no warning). The model loads (receiving a warning), and params.campaign_id is successfully passed (can be successfully registered in the console).
I think this is a problem with the router, but I'm not sure where to start. Any help would be appreciated.
Thanks for watching! I can post more information, just let me know what you need in the comments.