我想知道如何在加载我的默认模板/控制器(App Controller)之前强制加载模板具有最小加载时间(例如:3 秒)。我没有订阅,所以我唯一需要的是设置延迟加载模板的超时时间。
我已经尝试过发布 [here][1] 的类似解决方案,但现在的问题是 Router.route('/', { name: 'home'}); 永远不会被调用,我被困在 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;
}
};
}
});