2

My understanding is that Ember 1.11.0 deprecated resource in a router in favor of only using route. Per what I've read, the difference between the two was that a resource created a namespace. See: What is the difference between a route and resource in New Router API?

So the question is how do I namespace a route so that, in the example below, my comments Route, Controller, and View are not prefixed with 'Posts'?

App.Router.map(function() {
  this.route("posts", { path: "/" }, function() {
    this.route("new", { path: "/new" });
    this.route("comments", { path: "/comments" }, function() {
      this.route("new", { path: "/new" });
    });
  });
});
Community
  • 1
  • 1
cbonser
  • 23
  • 3

3 Answers3

3

Try passing resetNamespace: true to the route like

this.route("comments", { path: "/comments", resetNamespace: true }, function() {
  this.route("new", { path: "/new" });
});
blessanm86
  • 31,439
  • 14
  • 68
  • 79
  • 1
    While this is the easiest way to get rid of `this.resource`, `resetNamespace` is technically a private API so there's no guarantee that it'll stick around, which may or may not be better than sticking with `this.resource` which is officially deprecated. – hashemi May 21 '15 at 23:39
  • 3
    @Ahmad `resetNamespace` is a public API now. Refer to this [ember documentation](http://guides.emberjs.com/v2.0.0/routing/defining-your-routes/#toc_resetting-nested-route-namespace). and this [issue](https://github.com/emberjs/ember.js/issues/11251) – kushdilip Aug 17 '15 at 10:26
  • @Ahmad ohh.. I didn't notice. ha ha. – kushdilip Aug 17 '15 at 10:39
0

You can use the resetNamespace option for a route, something like this:

this.route('posts', {}, function() {
  this.route('comments', {resetNamespace: true});
});
Tim Tonkonogov
  • 1,099
  • 10
  • 14
0

Currently, there's no way of doing that using the public API without using this.resource, which is officially deprecated and slated for removal in Ember 2.0. Using resetNamespace is not officially supported as it is a private API so, technically, it may be removed at any time without warning.

The official solution to this problem is to refactor your application to accept that the Comments Routes and Templates are under Posts.

hashemi
  • 2,608
  • 1
  • 25
  • 31
  • Hopefully they expose some kind of public API for it in the future as an app with deeply nested routes (or even 3 levels of nesting) can end up with long and sometimes odd class names without it. – cbonser May 23 '15 at 11:51
  • @cbonser it's very likely that they will https://github.com/emberjs/ember.js/issues/11251 – hashemi May 24 '15 at 14:06