[英]Wait for page data in iron router - Meteor
是否可以等到頁面數據在頁面呈現之前加載? 在加載數據之前,我總是會看到notFound模板幾毫秒。
這是我的代碼:
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;
}
}
});
任何幫助將不勝感激。
您可以使用'loading'
掛鈎顯示您選擇的模板,而waitOn
中的訂閱尚未准備好。
激活鈎子:
Router.onBeforeAction("loading");
並設置加載模板:
Router.configure({
loadingTemplate: "loading"
});
<template name="loading">
loading... <!-- or display an animated spinner -->
</template>
您還可以在每個路由級別設置加載模板。
this.route("blah", {
path: "/blah",
loadingTemplate: "blahLoading"
});
這是我解決它的方式:
if (!game && this.ready()) {
this.render("notFound");
} else {
return game;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.