Reputation: 8212
This is my router
App.Router.map(function(){
this.resource('courses');
this.resource('course', { path: '/courses/:course_id'}, function(){
});
});
In my CoursesRoute I have -
actions: {
willTransition: function(transition) {
// how to access the intended transition or the intended model id
if(this.get('model.id') == 102) { // here model is not accessible
transition.abort();
}
// Since courses is a ArrayController I get all the courses inside this.get('controller.content')
// But how do I get the model ID of the selected course.
}
}
This is used in the courses template
{{#link-to 'course' this class='thumbnail course'}}
Upvotes: 1
Views: 500
Reputation: 1609
You should be able to find the ID of the context model like this:
actions: {
willTransition: function(transition) {
var contexts = transition.intent.contexts; // array of all context models
var contextID = contexts[0].id; // if you only expect one model, this is its ID
if(contextID == 102) { // now you can use the ID for your condition
transition.abort();
}
}
}
Upvotes: 2