lundi 23 novembre 2015

EmberJS varying length dynamic segments

I want to be able to achieve a URL structure that allows me to specify a varying number of dynamic segments in the ember router. My application is a simple product catalog where I will define products and place them within categories (on the backend) and send these down to ember to render to the screen.

For this I want the URLs to be similar to this:

  • /products/category
  • /products/category/subcategory
  • /products/category/subcategory/subsubcategory
  • etc...

So here the only 'real' route is products and as such I would define a ProductsRoute that will take each of the dynamic segments and pass those to my backend as parameters i.e.

ProductsRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.query('products', params); // { category: 'category', subcategory: 'subcategory', etc... }
  }
})

I of course cannot simply nest routes because then I would have only a fix number of dynamic segments available to me. Is there any way to define such a thing in the ember router?

Perhaps looking at this from a different perspective, is this not an optimal solution from an e-commerce standpoint? Should I be trying to achieve product categorisation in another way?




Aucun commentaire:

Enregistrer un commentaire