Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.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_Browser Refresh - Fatal编程技术网

Javascript 在meteor中检测浏览器刷新

Javascript 在meteor中检测浏览器刷新,javascript,meteor,iron-router,browser-refresh,Javascript,Meteor,Iron Router,Browser Refresh,我有一个名为“调查问卷”的容器模板,单击“下一步”按钮,该模板会一个接一个地显示问题。单击“下一步”按钮时,背景中有一些逻辑将为我提供下一个问题的路径。我将只更改问卷中的问题模板 <template name="questionnaire"> <h1>Snapwiz questionnaire</h1> <h3>Question</h3> {{> yield region="singleQuestion"}

我有一个名为“调查问卷”的容器模板,单击“下一步”按钮,该模板会一个接一个地显示问题。单击“下一步”按钮时,背景中有一些逻辑将为我提供下一个问题的路径。我将只更改问卷中的问题模板

<template name="questionnaire">
    <h1>Snapwiz questionnaire</h1>
    <h3>Question</h3>
    {{> yield region="singleQuestion"}}
    <button class="next">Next</button>
</template>

Template.questionnaire.events({
    'click .next':function(event,template){ 
           Meteor.call('nextQuestion',Router.current().params._id,function(err,res){
            if(res){
                Router.go('/question/'+res);
            }
        });
    }
});

Router.route('questionnaire',{
    yieldTemplates:{
        'question1':{to:'singleQuestion'}
    }
});

Router.route('question',{
    path:'question/:_id',
    action:function(){
        this.render('question'+this.params._id,{to:'singleQuestion'});
    }
});

斯内普维兹问卷
问题
{{>yield region=“singleQuestion”}
下一个
模板、问卷、事件({
'click.next':函数(事件、模板){
Meteor.call('nextQuestion',Router.current().params.\u id,函数(err,res){
如果(res){
Router.go('/question/'+res);
}
});
}
});
路由器路由('问卷'{
产量模板:{
“问题1”:{to:'singleQuestion'}
}
});
Router.route('问题'{
路径:'question/:_id',
行动:功能(){
render('question'+this.params._id,{to:'singleQuestion'});
}
});
有许多简单的问题模板,如“问题1”、“问题2”等,只需单击“下一步”按钮即可显示

当我们第一次点击链接“”时。默认情况下显示“问题1”模板。现在,当用户单击“下一步”按钮时,我们从服务器获取问题id并显示该问题模板。因此,单击“下一步”按钮将使我们进入“”,向我们显示问题2模板

到目前为止,一切进展顺利

但当我们将“”直接放入浏览器并重新加载时,问题就出现了。由于未加载该页面的容器,因此该页面为空

那么,最终的解决办法是什么呢?我觉得如果我们在路由器中检测到“热推代码”,那么我们也可以呈现容器模板,但我们应该如何做到这一点呢?。我不确定哪一个是最好的方法


感谢您的任何想法或帮助。

操作
回调中,您从未告诉Iron Router使用
问卷
作为布局模板。要解决此问题,只需调用
this.layout

action: function () {
    this.layout('questionnaire');
    this.render('question' + this.params._id, {to: 'singleQuestion'});
}

不,每次调用问题模板时都会传递我的父模板。也就是说,如果我在父级中保留了另一个显示问题列表的模板,那么每次呈现一个问题模板时,都会传递这些问题列表。我只是希望该区域被交付。你真的知道版面模板中的订阅会被销毁并重新创建吗?你检查过websocket的流量了吗?我希望这些订阅可以重复使用。