You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say you have a router setup like the following...
Router.map(function(){this.resource('students',function(){// This middle part of the URL is an ID that represents a student.this.resource('student',{path: ':student_id'},function(){this.route('milestones');});});});
Now, in your milestones route, you use prefetch as follows:
prefetch(params,transition){letstudentId=transition.params.student.student_id;// return some data fetch that depends on studentId}
When the page loads from scratch, eg. at a URL like mysite.com/students/1234/milestones, then everything works fine. It also works fine when doing a manual transition and passing in the student ID, like this:
But when we initiate the transition and pass the student model (in certain cases we already have it):
this.transitionTo('student.milestones',student);
... then we run into a problem in the milestones prefetch hook. Specifically, transition.params.student isn't populated, so our data fetch doesn't work. We've had to work around this by doing the following in prefetch:
Have you tried using this.paramsFor('student').student_id to retrieve the student_id parameter? I'm not familiar with accessing other routes' dynamic segments via the transition object, but I have a feeling it's not public API.
Good idea, but unfortunately that doesn't work either. this.paramsFor('student') is empty in prefetch() when the transition was passed a student object.
I wonder if the serialize method is run before or after the prefetch hook. This is definitely something I haven't looking into before, so might need some change to support.
I believe (in my example) the student route's serialize is run before the prefetch hook. But somehow the URL parameter returned in that serialize call is not making it to the prefetch arguments.
Let's say you have a router setup like the following...
Now, in your milestones route, you use prefetch as follows:
When the page loads from scratch, eg. at a URL like mysite.com/students/1234/milestones, then everything works fine. It also works fine when doing a manual transition and passing in the student ID, like this:
But when we initiate the transition and pass the student model (in certain cases we already have it):
... then we run into a problem in the milestones prefetch hook. Specifically,
transition.params.student
isn't populated, so our data fetch doesn't work. We've had to work around this by doing the following inprefetch
:... which obviously is very fragile and relies on internal Ember structures.
So seems like a bug that we can't always get the student ID from
transition.params
.The text was updated successfully, but these errors were encountered: