2

即使我明确定义了路由,我的应用程序也会继续生成默认路由。我认为我忽略了一个命名约定,但谷歌搜索、stackoverflowing、discuss.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模板渲染良好,没有错误。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。在 ThingsNewRoute 下的“自己的属性”下:

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

2 回答 2

1

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

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

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

目录结构应该是:

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

因为解析器希望ThingsNewRouteapp/routes/things/new.js

希望能帮助到你。

于 2013-10-12T17:24:03.930 回答
0

ThingsNewRoute应该是您的应用程序对象的属性。所以声明看起来像:

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

将 name 替换App为您分配给的变量Ember.Application.create();

于 2013-10-12T17:07:41.123 回答