最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What's the difference between this.route() and this.resource()? - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Apr 2, 2013 at 1:46 Marco Petersen asked Apr 2, 2013 at 1:23 Marco PetersenMarco Petersen 3313 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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');
  });
});

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

发布评论

评论列表(0)

  1. 暂无评论