lundi 4 juillet 2016

Go to new item route after creation in Emberjs

I've something like this in my route:

actions: {
  save(title, description) {
    const newCard = this.get('store').createRecord('card', { title, description } );
    newCard.save().then((card) => {
      // card.id contains the id of the new card
      this.transitionTo('cards.all'); // problem with this line
    });
  }
}

I want to go to the new card route after creating it. I can get the id of the new item from card.id. I've tried the following but of no use:

this.transitionTo('cards.card', card.id);

This throws some error since the cards.card route can't find the id in the params.

The following:

this.transitionTo('cards/' + card.id);

throws some error stating that cards/45 route not found but if the new item is created and I can navigate to it.

I'm using Ember 2.6.1.




Aucun commentaire:

Enregistrer un commentaire