[英]Wait for page data in iron router - Meteor
Is it possible to wait until the page data is loaded before page rendering? 是否可以等到页面数据在页面呈现之前加载? I always see the notFound template for a few milliseconds before the data is loaded. 在加载数据之前,我总是会看到notFound模板几毫秒。
Here is my code: 这是我的代码:
this.route('gamePage', {
path: '/game/:slug/',
onBeforeAction: filter,
waitOn: function() { return [Meteor.subscribe('game', this.params.slug)]; },
data: function() {
var game = Games.findOne({slug: this.params.slug});
if (!game) {
this.render("notFound");
} else {
return game;
}
}
});
Any help would be greatly appreciated. 任何帮助将不胜感激。
You can use the 'loading'
hook to display a template of your choice while the subscriptions in waitOn
are not yet ready. 您可以使用'loading'
挂钩显示您选择的模板,而waitOn
中的订阅尚未准备好。
Activate the hook: 激活钩子:
Router.onBeforeAction("loading");
And set a loading template: 并设置加载模板:
Router.configure({
loadingTemplate: "loading"
});
<template name="loading">
loading... <!-- or display an animated spinner -->
</template>
You can also set the loading template on a per-route level. 您还可以在每个路由级别设置加载模板。
this.route("blah", {
path: "/blah",
loadingTemplate: "blahLoading"
});
Here is how I solved it: 这是我解决它的方式:
if (!game && this.ready()) {
this.render("notFound");
} else {
return game;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.