Reputation: 15293
After successfuly my page loads, some point later I would like to redirect to next page with params.id
information. what is the correct way to retrive the params
any time?
here is my router.js:
export default Ember.Route.extend(Validation, {
model: function(params) { //where to store?
if(this.store.hasRecordForId('card-list', params.id)){
return this.store.peekRecord('card-list', params.id );
}
},
actions:{
goToNext(){
return;
this.transitionTo('cs2i.balance.balanceReview', 12 ); //how to get id?
},
Any one help me here? Thanks in advance.
Upvotes: 0
Views: 424
Reputation: 268
Your template has the id because of the model. So you can pass it directly into the action.
Note: this is linking directly to the same route, you'll need to do some math to get the next id in goToNext. But in the case where a record is deleted and another created the ID is not going to be consistent enough to do a simple +1. It would be better to have the actual ID of the next record. Which could be in the relationship of the API. Then you could do something like model.previousId instead of model.id.
// route.js
export default Ember.Route.extend(Validation, {
model: function(params) {
if(this.store.hasRecordForId('card-list', params.id)){
return this.store.peekRecord('card-list', params.id ;
}
},
actions:{
goToNext(paramId) {
this.transitionTo('cs2i.balance.balanceReview', paramId);
},
}
});
// template.hbs
<button {{action 'goToNext' model.id}}></button>
Upvotes: 1
Reputation: 1232
It depends where you want to call the route transition from.
If you call the transition from the router, then just save the params data (or just the id) to a local variable in the router.
If the transition is done in a component, pass in the params data (or just the id) as part of the model to the component.
Upvotes: 0