为什么我的余烬路由没有使用?

时间:2014-11-05 17:17:30

标签: ruby-on-rails ember.js

我开始使用带有Rails 4.1的ember-rails开发Ember。

定义了以下路线:

MyApp.Router.reopen({
    rootURL: '/mycontroller/'
})
MyApp.Router.map () ->
    this.route('welcome')

当我访问网址http://mysite/mycontroller/welcome时,welcome模板未呈现,但index模板已呈现。

DEBUG: -------------------------------
DEBUG: Ember      : 1.8.0 
DEBUG: Ember Data : 1.0.0-beta.11 
DEBUG: Handlebars : 1.3.0 
DEBUG: jQuery     : 1.11.1 
DEBUG: ------------------------------- 
Attempting URL transition to / 
generated -> route:application Object {fullName: "route:application"} ember.js?   body=1:15359
generated -> route:index Object {fullName: "route:index"} 
Transition #0: application: calling beforeModel hook 
Transition #0: application: calling deserialize hook 
Transition #0: application: calling afterModel hook 
Transition #0: index: calling beforeModel hook 
Transition #0: index: calling deserialize hook 
Transition #0: index: calling afterModel hook 
Transition #0: Resolved all models on destination route; finalizing transition. 
generated -> controller:application Object {fullName: "controller:application"} 
Could not find "application" template or view. Nothing will be rendered Object {fullName: "template:application"} 
generated -> controller:index Object {fullName: "controller:index"} 
Rendering index with default view <(subclass of Ember.View):ember307> Object {fullName: "view:index"} 
Transitioned into 'index' 
Transition #0: TRANSITION COMPLETE. 

为什么我的路线不被理解?

1 个答案:

答案 0 :(得分:1)

默认情况下,Ember路由要求路由前URL中的哈希符号。要导航到welcome路线,网址应为http://mysite/mycontroller/#/welcome

如果您不喜欢这种行为,可以通过让Ember与浏览器的历史记录API进行交互来禁用它:

App.Router.reopen({
  location: 'history'
});

然后,您可以按预期使用网址http://mysite/mycontroller/welcome

Here are the docs on Ember URL types