Search code examples
meteoriron-router

Direct to Specific Route when meteor auto refreshes


Im using meteor + Iron Router and I would like to handle (in the onbefore web hook) the case where meteor auto refreshes all connected clients and redirect to the home route ('/').

Is there a flag to determine when a refresh is caused by meteor live updating vs a client triggered refresh?


Solution

  • An auto-refresh triggered by a code change leaves Session variable values in-tact, whereas a client-triggered refresh will reset them all to null. So, if I understand you correctly, you could check for the presence of a Session variable in the Meteor.startup callback on the client and call Route.go('/') if it's null. Example:

    if (Meteor.isClient) {
        Meteor.startup(function() {
            if (!Session.get('keyKnownToHaveValue')) {
                Route.go('/');
            }
        });
    }