commadelimited
commadelimited

Reputation: 5119

Fire method each time route slug changes

I have a Router set up which looks like this:

Social.Router.map(function() {
    this.resource('accounts', function(){
        this.resource('account', { path: ':account_id'});
    });
});

When the account route is entered I'm using the activate method to do some DOM manipulation.

Social.AccountRoute = Ember.Route.extend({
    activate: function(){
        console.log('entered the account route')
    }
});

This works great, the first time the account route is entered. Problem is that I have the ability to change from account to account without leaving the account route. Meaning that I can go from:

account/1

to

account/2

but the activate method only fires one time, the first time I enter the account route. Is there a method that will fire every time the account_id slug changes?

Upvotes: 2

Views: 408

Answers (2)

Dan Gebhardt
Dan Gebhardt

Reputation: 3281

activate and deactivate are only triggered when entering a new route. However, the methods model, setupController, and serialize will be called with each change of /account/:account_id. (Edit: as pointed out by @mavilein in the comments, model will only be called when triggered by a URL change, and I left off renderTemplate).

Regardless, your routes and controllers shouldn't be concerned with DOM manipulation. Leave that to your views and templates by binding to significant values or observing changes in your controller(s).

Upvotes: 2

mavilein
mavilein

Reputation: 11668

Not a very intuitive solution, but there are 3 methods that are executed every time the model changes:

  • serialize
  • setupController
  • renderTemplate

Upvotes: 4

Related Questions