【问题标题】:Ember: loading Template not working when promise returned from Application RouteEmber:当应用程序路由返回承诺时,加载模板不起作用
【发布时间】:2014-12-16 00:11:38
【问题描述】:

不明白为什么下面的场景没有加载加载模板

App = Ember.Application.create()

App.Router.map ->
  this.resource 'dashboard', {path: "/"}

App.ApplicationRoute = Ember.Route.extend
  beforeModel: ->
    new Ember.RSVP.Promise (resolve) ->
      Ember.run.later ->
        resolve()
      , 3000

App.DashboardRoute = Ember.Route.extend      
  model: ->
    ['red', 'yellow', 'blue']

http://emberjs.jsbin.com/jageg/2/edit?html,js,output

documentation 我了解到,如果路径为dashboard 的路由返回不会立即解析的承诺,Ember 将尝试在层次结构中找到它可以转换到的加载路径。

谢谢。

【问题讨论】:

标签: ember.js routes loading


【解决方案1】:

是的,父资源的加载路径会放在父资源的{{outlet}}中。不幸的是,您阻塞了最顶层的资源,因此 Ember 无法呈现应用程序模板,因此它正在加载路由。

如果你阻塞低一级,它会命中应用程序资源的加载路径,也就是loading

http://emberjs.jsbin.com/babuzi/edit?html,js,output

【讨论】:

  • 非常感谢您的回复。但是,在我的真实示例中,我正在将当前用户加载到应用程序路由中,如果服务器由于某些原因而关闭,我将无法先显示loading 模板,也无法稍后显示error 模板。那么加载当前用户数据的最佳方法是什么。我需要当前用户,因为我会根据用户的状态执行授权策略。
  • 我遇到了完全相同的问题。你找到解决这个问题的好方法了吗?我能想到的唯一解决方案是将整个应用程序放在嵌套路由中(“example.com/app”),这样您就可以将application 模型移动到app.. 感觉不是正确的解决方案虽然..
  • 在最新版本的 Ember 中,应用模板上方存在加载路径。
猜你喜欢
  • 1970-01-01
  • 2013-01-26
  • 2014-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-24
  • 1970-01-01
  • 2016-02-02
相关资源
最近更新 更多