Search code examples
javascriptmeteoriron-router

Meteor JS: Iron Router Refresh Function


I couldn't find anything regarding this topic. What I am trying to do is when the user refreshes the page, iron router reroutes the user to a different template.

Something along the lines of

Router.onBeforeAction(function(){
  //If(refresh) reroute to home template
  //Else this.next()
});

Does iron router have anything that does the functionality?

Thank you for your time, LL


Solution

  • Thank you for the idea below9k! Here is what I went with.

    In my first form template:

    Template.form1.onRendered(function(){
      Session.set('formState', true);
    })
    

    In iron router function:

    Router.onBeforeAction(function(){
      if(Session.get('formState')){
        this.next();
      }else{
        Router.go('form1');
      }
      },
      {only: ['form2', 'form3']}
    );
    

    Thanks again for the answer! Works like a charm.

    LL