我想知道如何在加载我的默认模板/控制器(App Controller)之前强制加载模板以获得最小加载时间(例如:3秒)。我没有订阅,我唯一需要的是设置延迟loadTemplate。
我已经尝试了[此处] [1]发布的类似解决方案,但现在的问题是Router.route(' /',{name:' home&#39 ;});永远不会被调用,我被困在loadingTemplate页面上。
我将我的应用程序部署到http://ns-timeout.meteor.com/,所以任何人都可以查看我的console.logs()......
非常感谢任何帮助。
非常感谢
Router.configure({
layoutTemplate: 'AppController',
loadingTemplate: 'loading',
waitOn: function() {
var hasWaitTimePassed = new ReactiveVar(false);
var waitFor = 3000; // Wait for 3 sec
var stopped = false;
Meteor.setTimeout(function() {
console.log('setTimeOut() hasWaitTimePassed :'+ hasWaitTimePassed.get());
console.log('setTimeOut() stopped :'+ stopped);
if (!stopped) {
hasWaitTimePassed.set(true);
console.log('setTimeOut() if(!stopped) : hasWaitTimePassed.set(true):'+ hasWaitTimePassed.get());
console.log('setTimeOut() if(!stopped): '+ stopped);
}
}, waitFor);
return {
ready: function() {
// hasWaitTimePassed is a reactive source, so this should do just fine
console.log('return { ready function() hasWaitTimePassed :'+ hasWaitTimePassed.get());
console.log('return { ready function() stopped :'+ stopped);
return hasWaitTimePassed.get();
},
stop: function() {
console.log('return { stop function() hasWaitTimePassed :'+ hasWaitTimePassed.get());
console.log('return { stop function() stopped :'+ stopped);
// Stopping should prevent the hasWaitTimePassed becoming true.
stopped = true;
}
};
}
});