lundi 3 juillet 2017

Ember not calling setupController of router

So, I have two paths in my route. I created the two routes as the doc recommends.

My router is the following:

// router.js
Router.map(function() {
  this.route('photos');
  this.route('photo', { path: '/photo/:photo_id' });
});

If I visit firstly the route /photo/ID and then go to /photos, it will only show one object on the latter. (wrong)

If I visit /photos first it shows all the objects and I can go to /photo/ID later on and it will be fine. (right)

I want to make it work both ways. How to do this? You can see my code for each route down below:

// photo.js
export default Ember.Route.extend({
  model(params) {
    return this.get('store').findRecord('photo', params.photo_id);
  }
});

// photos.js
export default Ember.Route.extend({
  setupController(controller, model) {
    let photos = this.get('store').findAll('photo');
    console.log('add all...');
    // convert to an array so I can modify it later
    photos.then(()=> {
      controller.set('photos', photos.toArray());
    });
  },
});

I can always call the findAll() function regardless where the user goes, but I don't think this is smart.




Aucun commentaire:

Enregistrer un commentaire