![](/img/trans.png)
[英]'Ember generate resource' command end up adding this.route() to router.js
[英]What's the difference between this.route() and this.resource()?
我知道路由用於將URL映射到模板,但顯然你可以用this.route或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');
});
});
你是否只想使用this.resource來定義路由的子路由,還是有其他理由我沒有得到?
你是否只想使用this.resource來定義路由的子路由,還是有其他理由我沒有得到?
這是基本的想法。
還要記住,路由器始終指向當前路由。 它無法轉換為資源。 在幕后,ember自動在每個資源下面生成一個“索引”路徑,所以即使你定義了這樣的東西:
App.Router.map(function() {
this.resource("about", { path: "/about" });
});
你最終得到這個:
App.Router.map(function() {
this.resource('about', { path: '/about' }, function() {
this.route('index');
});
});
這是在ember 3.x中折舊的。 沒有了this.resource()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.