"New"路由在 ember-app-kit 中被忽略



即使我显式定义了路由,我的应用程序也会继续生成默认路由。我想我忽略了一个命名约定,但谷歌搜索、堆栈溢出、讨论.emberjs.com'ing和对计算机的老式诅咒还没有让我得到任何地方。

应用/路由器.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模板呈现良好,没有错误。余烬日志记录的输出:

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。在ThingsNewRoute下的"拥有属性"下:

routeName: things.newSend
controller: (generated things.new controller)
lastRenderedTemplate: things.new
teardownOutletViews: [ function() { ... } ]

在 ember-app-kit 中,要让解析器正确选取您的路由,您必须将它们放在子目录中。

例如,对于您的用例,通过具有以下路由器映射:

Router.map(function(){                 
  this.resource('things', function() {
    this.route('new');                 
  });                                  
}); 

目录结构应为:

app/
   ...
   routes/
      things/
        new.js
        ...

因为解析程序希望在app/routes/things/new.js中找到路由ThingsNewRoute

希望对您有所帮助。

ThingsNewRoute应该是应用程序对象的属性。因此,声明将如下所示:

App.ThingsNewRoute = Em.Route.extend({
    ....
})

将名称App替换为您为其分配了Ember.Application.create();的变量

相关内容

  • 没有找到相关文章

最新更新