Router "this.resource" gone from documentation (v1.11.0)


#1

The “Defining your routes” section in the v1.11.0 guide on emberjs.com has removed the documentation for this.resource. Is there a reason for this? I can’t find anything about it being deprecated. Issue #10708 seems to hint at this and the change happened 22 days ago but there no real comment about why.

On an unrelated note: I can’t use any hotkeys or copy/paste on this forum; otherwise I would have added links.


#2

this.resource has not been deprecated just yet, but it is planned to be deprecated before 1.13. We removed it from the guides for 1.11, because we do not advise folks to make new apps/routes/etc as resources (it seems bad to suggest folks use a thing we intend to remove when the recommended alternative is ready to use today).


#3

I see now that you can achieve the same thing with just nested routes; hadn’t read the docs closely. The old resource/route stuff divide always confused me so good on unifying it. Good show, thanks! Oh, and now my hotkeys are working again. Strange night.


#4

By the way, when you run ember g resource any, it still creates a declaration in the router as for a resource:

this.resource('any', function() {});

I believe in view of the forthcoming deprecation it should be fixed.


#5

Seems like a good thing to remove from ember-cli, mind making an issue?


#6

Sure thing, will be there in 10 mins


#7

Sounds a lot like a deprecation; perhaps a soft one, I wasn’t aware of the change at all.

Are we able to mark such plans onto a roadmap / rough notes?


#8

I ran into this the other day - I remembered vaguely seeing some talk of resource going away but it was still odd to see it missing from the docs when ember-cli was happily generating a resource route.

It’s good that that’s being changed but one idea might be to do what the Django docs do and include little panels with headers like ‘Changed in 1.10’, ‘New in 1.11’ or even just ‘Note, this document used to refer to…’


#9

Very very new ember/ember-cli user here.

Does this mean I should or should not use ember g resource for a REST-ish set of routes?


#10

Quite said to see it go.

I used to use this.resource to define dashboard resource that has AuthenticatedOnlyMixin and protects all its childs against unauthenticated access. Currently, after converting to route, not only all my routes are now prefixed with dashboard.... but also I have one extra level of directories in both controllers and routes folder…

I’ve also used it to define dashboard specific layout (think of it as a application but only for authenticated users) that I was unable to put into application template due to login/register pages having a different theme.

Any better workaround?

Defining Authenticated only mixing on every single top-level route inside a dashboard route just feels wrong to me.


#11

@grabbou You can reset the namespace on route with an option:

this.route('dashboard', {}, function() {
  this.route('top-level-route', {resetNamespace: true});
});

Basically, passing resetNamespace: true is the same as calling resource.

Here is a complex router file for an example.


#12

Thanks, works like a charm :slight_smile:


#13

Recource is still gone from Ember docs and guides and at the same time there is no documentation about resetNamespace flag. This can cause a lot of problems for newcomers.