Reputation: 15538
I'm using Iron:router + Cordova in my Meteor project.
Since my app depends on Cordova libraries, I need to wait for Cordova to be ready.
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');
How can I wait until cordovaReady == true, then route to /config?
Upvotes: 1
Views: 128
Reputation: 20227
I believe you should be able to do:
onBeforeAction: function(){
if ( Session.get('cordovaReady') ) this.next();
else this.render('loading');
});
Assuming you have a loading template (ex: a spinner) named loading
.
Upvotes: 1