Using nested routes

I am trying to figure out a simple nested route that will give me the following hierarchy: Products → Product → Product Prices. So I want a list of products , open a product and then display all the prices for the product. I figured something like this would work:

this.resource(‘products’, {path: “/products”},function(){ this.resource(‘product’,{path: “/:product_id”},function(){ this.route(‘productprices’) }); }),

It complains that the router could not find route products.product

however this works just fine:

this.resource(‘products’, {path: “/products”},function(){ this.route(‘product’,{path: “/:product_id”}) }),

So I guess I am not sure what the correct multi-level netting protocol is. I tried looking for examples but could only find single nesting… Thanks!

You should format your code properly.

this.resource('products', { path: "/products" }, function() {
	this.resource('product', { path: "/:product_id" }, function() {
		this.route('productprices')
	});
})

You mentioned that it couldn’t find the route products.product. That’s because it doesn’t exist. Resources don’t take the prefix of their parent resource. So in the above, product.productprices is a valid route name, but products.product is not. The name of the route is just product. So you can either just refer to it by product, or you can declare it as products.product.

this.resource('products', { path: "/products" }, function() {
	this.resource('products.product', { path: "/:product_id" }, function() {
		this.route('productprices')
	});
})

The above creates 5 routes: products, products.index, products.product, products.product.index and products.product.productprices.

Thank you very much! i really appreciate it.No more pulling the hair out. Just have to wait for it to grow back :smile: