gpt4 book ai didi

javascript - 在 Iron Router 中等待页面数据 - Meteor

转载 作者:行者123 更新时间:2023-11-30 12:36:53 25 4
gpt4 key购买 nike

是否可以等到页面数据加载完毕再进行页面渲染?在加载数据之前,我总是会看到几毫秒的 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;
}
}
});

如有任何帮助,我们将不胜感激。

最佳答案

waitOn 中的订阅尚未准备好时,您可以使用 'loading' Hook 显示您选择的模板。

激活 Hook :

Router.onBeforeAction("loading");

并设置加载模板:

Router.configure({
loadingTemplate: "loading"
});
<template name="loading">
loading... <!-- or display an animated spinner -->
</template>

您还可以在每个路由级别设置加载模板。

this.route("blah", {
path: "/blah",
loadingTemplate: "blahLoading"
});

关于javascript - 在 Iron Router 中等待页面数据 - Meteor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25790614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com