Best practice in nested routing

Im going to use nested routes. Im now wondering, whats the best practice. See the following snipped from my router:

this.resource('items', function() {
  this.route('overview');
  this.resource('item', {path: '/:title'}, function() {
    this.resource('states', function() {
      this.route('state', {path: '/:title'});
    });
  });
});

so, the question is: Is it good practice to use resource for itemS (in plural) and nested in it the resource item (singular), which stands only for a placeholder for defining the dynamic segmented route. The resulting URL should be: domain.org/items/item1/states/inactive

Also, Im wondering if it is the right use of resources and routes in this case.

What do you guys thing? Does a common convention exist?

I’m fairly new to ember so take what I say with a grain of salt. I’m not sure what your use case is, but I might be more inclined to do something like this:

this.resource('items', { path: 'items' }, function() {
  this.route('overview')
})
this.resource('item', {path: '/item/:title'}, function() {})

and then use queryParams for your states.

Hope this helped a bit.

Resource is on it’s way out. Probably best not to use resource.

things to consider between the two

The way you have but using route in stead of resource:

  • Reference the item route as transitionTo(‘items.item’)
  • actions can bubble from item → items
  • if you use pods structure, which is the future, then you folders will be items/item/route.js, component.js, template.js
  • if you specify a model for your items route then it will get loaded when you hit the item route

The way @MattEddy suggested:

  • Reference the item route as transitionTo(‘item’)
  • actions do not bubble from item → items
  • If you use pod structure your folders will be item/route.js … and items/route.js…
  • if you specify a model for your items route then it will NOT get loaded when you hit the item route