Javascript Meteor-当为路由器获取数据时,页面刷新会导致闪烁
如果我刷新使用iron router设置中的数据查询的meteor页面,该页面将加载模板但不包含数据,然后显示加载模板,然后显示包含数据的页面。我想避免正在发生的页面闪烁。这是我的路由器代码:Javascript Meteor-当为路由器获取数据时,页面刷新会导致闪烁,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,如果我刷新使用iron router设置中的数据查询的meteor页面,该页面将加载模板但不包含数据,然后显示加载模板,然后显示包含数据的页面。我想避免正在发生的页面闪烁。这是我的路由器代码: this.route('/stories/:_id', function () { if (!Meteor.user() && !Meteor.loggingIn()) { Router.go('home'); } else { var stor
this.route('/stories/:_id', function () {
if (!Meteor.user() && !Meteor.loggingIn()) {
Router.go('home');
} else {
var story = Stories.findOne({ _id: this.params._id });
this.render('showStory', { data: story });
}
});
我也尝试过这个设置,并将登录验证移到onBeforeAction
this.route('showStory', {
path: '/stories/:_id',
data: function () {
return Stories.findOne({ _id: this.params._id });
}
});
使用此设置刷新页面时,我会看到我的404页面,然后是加载模板,然后是包含数据的正确模板。尝试使用此设置
Router.map(function () {
this.route('showStories', {
path: '/stories/:_id',
waitOn: function(){
return Meteor.subscribe("Stories"); //we make de subscription here
},
data: function(){
if(! Meteor.user()){
this.render('/') //or sign-up template whatever template you want if user its not loged in
}else{
return Stories.findOne({_id: this.params._id});
}
}
});
});
已经测试过并且可以正常工作您有加载模板吗?您的订阅放在哪里?我有一个加载模板,需要的订阅在Router.configure中