EmberJS - 在路线和用户体验中加载模型

时间:2020-12-10 21:10:29

I load my model in Route's "model" hook. The route does not transition until the model data is fetched.

我在Route的“模型”钩子中加载我的模型。在获取模型数据之前,路径不会转换。

Browser remains in old route until the data comes in, resulting in bad user experience.

浏览器保持旧路由,直到数据进入,导致糟糕的用户体验。

What is the best practice to load model in Ember 2.0 so that we can present atleast the new template to user without data for better user experience?

在Ember 2.0中加载模型的最佳实践是什么,以便我们可以向用户提供至少新模板而无需数据以获得更好的用户体验?

1 个解决方案

#1


1  

Ember provides a 'loading' route for you while your model for any route is loading. You could copy your new template, create a loading.hbs template for the new route, and paste it in there so it will show while the model hook resolves the model.

当您的任何路线的模型正在加载时,Ember为您提供“加载”路线。您可以复制新模板,为新路径创建loading.hbs模板,然后将其粘贴到其中,以便在模型挂钩解析模型时显示。

This is well documented in the Ember Guides: http://guides.emberjs.com/v2.1.0/routing/loading-and-error-substates/

这在Ember指南中有详细记载:http://guides.emberjs.com/v2.1.0/routing/loading-and-error-substates/

#1


1  

Ember provides a 'loading' route for you while your model for any route is loading. You could copy your new template, create a loading.hbs template for the new route, and paste it in there so it will show while the model hook resolves the model.

当您的任何路线的模型正在加载时,Ember为您提供“加载”路线。您可以复制新模板,为新路径创建loading.hbs模板,然后将其粘贴到其中,以便在模型挂钩解析模型时显示。

This is well documented in the Ember Guides: http://guides.emberjs.com/v2.1.0/routing/loading-and-error-substates/

这在Ember指南中有详细记载:http://guides.emberjs.com/v2.1.0/routing/loading-and-error-substates/