I’ve recently came across a very interesting part of Ember’s router. Our app is very contextual. We have a few core models (resources) that are interacted in different ways depending on how you look at them. Here’s is one example. I’ll express this in routes because it’s easier to understand.

We interact with the Deal model when looking at them through a Company, Contact or simply straight on. Now, through reasons unknown to me, the router is designed to make this difficult to do. The core problem is that the router does not namespace resources. Also there is no way to distinguish how to get to the various new routes. The router creates
these routes:

CompaniesRoute

ContactsRoute

DealsRoute

DealsNewRoute

There is no mention of a CompaniesDealsNewRoute or a ContactsDealsNewRoute. Actually there is no way to even get to them anyways: there is only deals.new. So how can I create a unique route for these situations? Don’t use resources. Ok, but then I nesting routes is not allowed. This design decision is going to make programming our application extremely difficult. At the moment, I don’t think their is a (decent) work around for this.

Would be nice if the resources also automatically set up the “real” nested namespaces and reflected this for controllers and views as well IMO. then you could have folder hierarchies that match your namespacing and all is well Strange why this wasn’t considered!?

It should be possible to have the “string” of previous resources available at each level. The resource could create a new Resource instance, and the function be inserted on this instance as a ResourceBuilder (to build child resources), then the next resource could be nested on the previous resource with a pointer back to the parent resource - composite builder pattern. I sure hope this makes it into router v3+, perhaps at the Ember 1.2 stage

Any news on this? I’ve been facing this limitation and I can’t not agree on how this was made. It’s frustrating and foten ember is advertised as a javascript framework for large apps, but this proves wrong when you start fighting against the framework when you app grows.

I think given the current router and this situation, this solution makes the most sense. This gets kind of messy though, because not included here are the routes and paths for companies and contacts.

Coming from the rails world, I’d love to have these resources work similarly where I can have each of these nested resources support multiple dynamic segments, too. Like ‘/company/12/deals/3243’. I have yet to see this brought up on the boards or on StackOverflow. Is there a different way we should be doing this with ember?

I have also struggled with this. It would seem trivial to implement a deeply nested UI with the marketing around ember js. But scratch the surface and to an outsider or newbie it seems a bit complex. I would love to see an explicit guide that shows a deeply nested router example perhaps three or four levels deep. It is not clear to me if this is even possible in the current state of ember.

Below might be a somewhat contrived example but would this even be possible? A hypothetical directory of libraries and the books in each library. The UI would be be tree like where you can drill down inside the nested structure. I can’t seem to find any examples where the resource nesting is more than two deep.

Now, through reasons unknown to me, the router is designed to make this difficult to do. The core problem is that the router does not namespace resources.

We made this choice originally because chaining names would lead to some very long class names, i.e. App.CompaniesDealsNewController is a pretty long name. In general, I also think super deeply nested routes is a bad idea. It really does get ugly pretty quick.

However, we have had some discussion about this (I think there’s even an open ticket) and I expect we’ll be thinking more about ways to make some of these cases easier.