我正在尝试在 ember 应用程序工具包中定义嵌套资源。我的文件结构不正确吗?添加嵌套资源时,出现以下异常:
Error: Assertion Failed: The URL '/pages.index' did not match any routes in your application
通过简单地注释掉定义嵌套“页面”资源的函数,应用程序可以正确加载并显示页面模板。
路由器代码:
var Router = Ember.Router.extend();
Router.map(function() {
this.route('component-test');
this.route('helper-test');
this.resource('pages', {path: '/pages'}
// if this line is commented out, no error (index route is not called though)
, function() { this.resource('page', {path: ':page_id'}); }
);
});
export default Router;
文件结构如下:
$ ls -R
component-test.js helper-test.js pages
component_test.js index.js pages.js
./pages:
index.js page.js
页面路线:
export default Ember.Route.extend({
model: function() {
return [{title: "One", _id: "one"}, {title: "Two", _id: "two"}];
//this.store.find('page');
}
});
页面/索引路线:
export default Ember.Route.extend({
model: function() {
return this.modelFor('page');
}
});
pages/index 路由的 es6 生成模块如下所示:
define("appkit/routes/pages/index",
["exports"],
function(__exports__) {
"use strict";
__exports__["default"] = Ember.Route.extend({
model: function() {
return this.modelFor('page');
}
});
});