How to use Meteor FlowRouter.reload()

I’ve found the FlowRouter documentation for FlowRouter.reload(), but I’ve been unable to find specific code examples and haven’t been able to make it work.

My app has a template that uses some clever javascript (Isotope) to reposition elements as the page resizes. If the user navigates away, resizes the browser window, and then returns, the page is messed up - nothing redraws because nothing is triggered (a benefit of FlowRouter, usually!).

This is my route. How would I use FlowRouter.reload() to reload/refresh just the “work” template area reliably on EVERY access of the template? It would also be useful to know what to do differently to refresh the window, as opposed to just the template area.

`FlowRouter.route( '/work', {
  action: function() {
    BlazeLayout.render( 'body-static', { 
      content:  'work',
    });
  },
});`

You could use triggers combined with FlowRouter.reload to achieve this. Something like the following will always reload the defined route (once) when accessed.

let fireReload = false;

FlowRouter.route('/', {
  triggersEnter: [reloadCheck],
  action() {
    console.log('Awesome action!');
  },  
  triggersExit: [routeCleanup]
});

function reloadCheck(context, redirect, stop) {
  if (fireReload) {
    console.log('Reloading ...');
    FlowRouter.reload();
    stop();
  }
}

function routeCleanup() {
  fireReload = !fireReload;
}
2 Likes

That worked a charm!!!

For unknown mysterious reason, the action() after triggersEnter seemed to prevent the layout from loading.

So, I have changed the reloadCheck console.log to write,

console.log('Hugh is Awesome and also reloading screen...'); 

Now, whenever anyone re-accesses this screen ever, “Hugh is Awesome” will be generated in the console log and in the universe.

Sound effects that go with this: “Beautiful. OMG BEAUTIFUL. Hugh IS awesome!!!”