Meteor 的Iron:router:如何基于Session 变量(cordovaReady)渲染模板?

Meteor's Iron:router: how to render template based on Session variable (cordovaReady)?

我在我的 Meteor 项目中使用 Iron:router + Cordova。

由于我的应用程序依赖于 Cordova 库,因此我需要等待 Cordova 准备就绪。

client/lib/init.js

Session.set('cordovaReady', false);
var initCordova = function() {

    /*
     * init filetransfer cordova plugin
     */
    var fileTransfer = new FileTransfer(),
        storageDataDirectory = cordova.file.dataDirectory;

    // make them global
    window.fileTransfer = fileTransfer;
    window.storageDataDirectory = storageDataDirectory;

    Session.set('cordovaReady', true);

};
initCordova();

shared/lib/routing.js:

Router.configure({
    loadingTemplate: 'loading',
    layoutTemplate: 'common' 
});

Router.route('/config', {
    name:'config',
    template:'configuration',
    onBeforeAction: function(){
    // TODO: allow template rendering only once cordovaReady session variable is == true

    this.layout(null);
    this.render("configuration");
 }
})

client/app.js

Router.go('config');

如何等到 cordovaReady == true,然后路由到 /config

我相信你应该可以做到:

onBeforeAction: function(){
  if ( Session.get('cordovaReady') ) this.next();
  else this.render('loading');
});

假设您有一个名为 loading.

的加载模板(例如:微调器)