我开始使用带有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.
为什么我的路线不被理解?
答案 0 :(得分:1)
默认情况下,Ember路由要求路由前URL中的哈希符号。要导航到welcome
路线,网址应为http://mysite/mycontroller/#/welcome
。
如果您不喜欢这种行为,可以通过让Ember与浏览器的历史记录API进行交互来禁用它:
App.Router.reopen({
location: 'history'
});
然后,您可以按预期使用网址http://mysite/mycontroller/welcome
。