Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4829

Accessing a route directly via URL, the data is not populated

$
0
0

@jas wrote:

I have a nested route setup as I would like to have my templates nested as well. The route setup looks like this:

...
  this.route('posts', function() {
    this.route('post', {path: ':post_id'}, function() {
      this.route('comments',  {path: 'comments'}, function() {
        this.route('comment',  {path: ':comment_id'});
      });
    });
  });
...

Potentially, my URL could look something like this:
/posts/:post_id/comments/:comment_id

If I navigate via {{link-to}} then I have no problem, however, if I go directly to a specific URL via the browser, that's when things going wrong. Imagine that my comments page lists the comments associated with the post (post_id) I'm looking at. The problem is going there directly, like typing in /posts/123/comments/56 doesn't load the list of comments, only the comment itself. Here is how my routes are setup:

// routes/posts.js
...
model() {
	return this.get('store').findAll('post');
}
...

// routes/posts/post.js
...
model(params) {
	return this.get('store').findRecord('post', params.post_id);
}
...

// routes/posts/post/comments.js
...
model(params) {
	let post=this.modelFor('posts/post');
	return post.get('comments');

}
...

// routes/posts/post/comments/comment.js
...
model(params) {
	let post=this.modelFor('posts/post');

	return post.get('comments').then(function(results){
		return results.store.findRecord('comment', params.comment_id);
	});
}
...

How do I populate/hydrate the post's comments list when I go directly to a comment in that post URL rather than navigating there via link-to?

If I type in /posts/123/comments/56, no list is displayed from the comments.js template. If I type in /posts/123/comments, only the first comment is displayed from the comments.js. Any thoughts?

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles