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

I understand that routes are used to map URLs to patterns, but apparently you can either define routes using 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');
  });
});

Are you just using this.resource if you want to define routing routines, or is there any other rationale that I don't get?

+5
source share
1 answer

Are you just using this.resource if you want to define routing routines, or is there any other rationale that I don't get?

This is the main idea.

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

Also keep in mind that the router always points to the current route. He cannot go to the resource. Behind the scenes, ember automatically generates an “index” route under each resource, so even if you define something like this:

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

:

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

All Articles