Brian
Brian

Reputation: 946

Ember.js Route: How to avoid infinite loop when refreshing parent route from child setupController

I have two nested routes, projects and projects/project. Whenever I open a project, I would like the projects route to be refreshed.

What I am doing know is to call a controller function during the setupController hook (that will end up calling refresh in the projects route). Something like this:

  // project route
  setupController: function(controller, model) {
    this.controllerFor('projects').send('search');
    controller.set('model', model)
  }

  // projects controller
  actions: {
    search: function() {
      // do other things
      this.send('refreshModel');

    }
  }

  // projects route
  actions: {
    refreshModel: function() {
      this.refresh();
    }
  }

The problem is that, when the refresh function is called, it not only refreshes the current route, but also all the children routes, meaning that this setupController hook will be executed again, creating this infinite loop.

Is there a way to make Ember refresh just the current route, ignoring its children?

Thank you.

Upvotes: 1

Views: 365

Answers (1)

locks
locks

Reputation: 6577

To answer directly, there is no way to only refresh the parent route. You might, however, be able to just reload the model and still get the behaviour you need.

See the relevant API documentation for DS.Model#reload.

Upvotes: 0

Related Questions