Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In prefetch, transition.params is not fully populated when a parent model was provided to the transition #12

Open
joshwiseman opened this issue Jun 17, 2016 · 4 comments

Comments

@joshwiseman
Copy link

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) {
    let studentId = 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:

this.transitionTo('student.milestones', studentId);

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:

let studentId = transition.params.student.student_id || transition.intent.contexts[0].id;

... 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.

@nickiaconis
Copy link
Owner

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.

@joshwiseman
Copy link
Author

Good idea, but unfortunately that doesn't work either. this.paramsFor('student') is empty in prefetch() when the transition was passed a student object.

@nickiaconis
Copy link
Owner

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.

@joshwiseman
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants