Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor-当为路由器获取数据时,页面刷新会导致闪烁_Javascript_Meteor_Iron Router - Fatal编程技术网

Javascript 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

如果我刷新使用iron router设置中的数据查询的meteor页面,该页面将加载模板但不包含数据,然后显示加载模板,然后显示包含数据的页面。我想避免正在发生的页面闪烁。这是我的路由器代码:

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中