Marco Petersen
Marco Petersen

Reputation: 331

What's the difference between this.route() and this.resource()?

I understand that routes are used to map URLs to templates, but apparently you could either define routes with this.route or this.resource

App.Router.map(function() {
  this.route("about", { path: "/about" });
  this.route("favorites", { path: "/favs" });
});

App.Router.map(function() {
  this.resource('posts', { path: '/posts' }, function() {
    this.route('new');
  });
});

Do you just use this.resource if you want to define subroutes to a route or is there another rationale I'm not getting?

Upvotes: 6

Views: 1541

Answers (2)

Thilina Dinith Fonseka
Thilina Dinith Fonseka

Reputation: 644

this is being depreciated in ember 3.x. there is no more this.resource()

Upvotes: 0

Mike Grassotti
Mike Grassotti

Reputation: 19050

Do you just use this.resource if you want to define subroutes to a route or is there another rationale I'm not getting?

That's the basic idea.

  • resource = parent (usually a noun)
  • route = child (often a verb)

Also keep in mind that the router always points to a current route. It cannot transition to a resource. Behind the scenes ember automatically generates an 'index' route underneath every resource, so even if you define something like this:

App.Router.map(function() {
  this.resource("about", { path: "/about" });
});

you end up with this:

App.Router.map(function() {
  this.resource('about', { path: '/about' }, function() {
    this.route('index');
  });
});

Upvotes: 8

Related Questions