即使我明确定义了路由,我的应用程序也会继续生成默认路由。我认为我忽略了一个命名惯例,但谷歌搜索,堆栈流动,讨论emberjs.com以及对计算机的粗略诅咒并没有让我到任何地方。
应用程序/ router.js
var Router = Ember.Router.extend();
Router.map(function(){
this.resource('things', function() {
this.route('new');
});
});
export default Router;
应用程序/路由/ things_new.js
var ThingsNewRoute = Em.Route.extend({
model: function() {
window.console.log('hello hello');
return this.store.createRecord('thing');
}
});
export default ThingsNewRoute;
访问http://localhost:8000/#/things/new
模板渲染得很好,没有错误。 ember的日志输出:
generated -> route:application Object {fullName: "route:application"} ember.js:415
generated -> route:things Object {fullName: "route:things"} ember.js:415
generated -> route:things.new Object {fullName: "route:things.new"} ember.js:415
generated -> controller:application Object {fullName: "controller:application"} ember.js:415
Rendering application with default view <(subclass of Ember.View):ember267> Object {fullName: "view:application"} ember.js:415
generated -> controller:things Object {fullName: "controller:things"} ember.js:415
Rendering things with default view <Ember._MetamorphView:ember283> Object {fullName: "view:things"} ember.js:415
generated -> controller:things.new Object {fullName: "controller:things.new"} ember.js:415
Rendering things.new with default view <Ember._MetamorphView:ember293> Object {fullName: "view:things.new"} ember.js:415
Transitioned into 'things.new' ember.js:415
Ember Debugger Active
问题在于:
generated -> route:things.new Object {fullName: "route:things.new"} ember.js:415
它不应该生成这个因为我定义它。是否有一些我没有遵循的文件命名约定?
另请参阅Chrome中的Ember Inspector。在&#34;自己的属性&#34;在ThingsNewRoute下:
routeName: things.newSend
controller: (generated things.new controller)
lastRenderedTemplate: things.new
teardownOutletViews: [ function() { ... } ]
答案 0 :(得分:1)
在ember-app-kit中,要让你的路线被解析器正确拾取,你必须将它们放在子目录中。
例如,对于您的用例,可以使用路由器映射:
Router.map(function(){
this.resource('things', function() {
this.route('new');
});
});
目录结构应为:
app/
...
routes/
things/
new.js
...
因为解析器需要在ThingsNewRoute
app/routes/things/new.js
希望它有所帮助。
答案 1 :(得分:0)
ThingsNewRoute
应该是应用程序对象的属性。声明如下:
App.ThingsNewRoute = Em.Route.extend({
....
})
将名称App
替换为您为其分配Ember.Application.create();