Search code examples
ember.jsember-dataember-cli

Don't request parent route's model


I've got a blog. Single blog-posts appear under /blog/post-title, a list of post under /blog/

Whenever I access a single blog-post like http://example.com/blog/post-title it also requests a list of posts from the parent-route:

enter image description here

For a single blog post the list of posts is not required. How can I prevent loading the parent's model (the list of posts)?

This is the router.js:

Router.map(function() {
  this.route('base', { 'path' : '/' }, function() {
    this.route('blog', { 'path' : 'blog/'}, function() {
      this.route('post', { 'path' : ':permalink' })
    })
  })
})

Solution

  • 1) Add a nested route 'index' under blog:

    Router.map(function() {
      this.route('base', { 'path' : '/' }, function() {
        this.route('blog', { 'path' : 'blog/'}, function() {
          this.route('index', { 'path': '/' });
          this.route('post', { 'path' : ':permalink' })
        })
      })
    })
    

    2) Move your logic from 'blog' controller to 'blog.index', also move template logic from blog to blog.index.