Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 579
Marco Petersen Avatar asked Apr 02 '13 01:04

Marco Petersen


1 Answers

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');
  });
});
like image 171
Mike Grassotti Avatar answered Oct 08 '22 13:10

Mike Grassotti