I’m building a app that will run in the web browser as well as on mobile devices (Cordova) and I would like to set a different root (/) route depending on the actual environment.
I tried it this way:
- Detect mobile environment in a client-side Meteor.startup() function (using Meteor.isCordova and navigator.platform detection) and set Session variables accordingly
- Retrieve these Session variables in the FlowRouter.route(), which is located under /lib
This did work, but I’m not convinced with this solution since docs state that code under /lib is always called before any code under /client or /server. So it may be just a “lucky” chance that my Session variables were set before FlowRouter.route() is being called.
Hence, I tried to improve this by moving the actual detection code (and the setting of the Session variables based on detection results) into a startup.js under /lib. This, however, causes a rather “unpredictable” behaviour. Sometimes, the startup code (still encapsulated in Meteor.startup()) is run before the FlowRouter.route(), sometimes after it. I’m just guessing that this depends on when Meteor actually loads the code.
I could also try to set the Session variables on a global level (i.e. outside Meteor.startup()), but I’m unsure if this is a “safe” way, since I would guess that intializing global objects like “Session” is not “guaranteed” at that early time.
So, what would be the “safe” way to set environmental Session variables that can be retrieved by FlowRouter’s routes to react on the current environment?