4

I've found the FlowRouter documentation for FlowRouter.reload(), but I've been unable to find specific code examples and can't get it working.

In my app, I have a template that uses some clever javascript (Isotope) to reposition elements as the page resizes. Sometimes the user navigates away, resizes the browser window, and then returns - to a messed up page that should refresh and redraw to reposition the elements for the re-sized window.

This is my route. How would I use FlowRouter.reload() to reload/refresh just the "work" template area? Alternatively, how would I use it to reload/refresh the whole layout template or window?

FlowRouter.route( '/work', {
  action: function() {
    BlazeLayout.render( 'body-static', { 
      content:  'work',
    });
  },
});
Deborah
  • 4,316
  • 8
  • 31
  • 45
  • Can't you just execute `$grid.isotope('layout')` when the size changes or when the document becomes active again? – Michel Floyd May 20 '16 at 06:07
  • I did try that, but I wanted to do it on FlowRouter's triggerEnter, and this function does not run any jQuery. Plus, I'd like to know how to use FlowRouter.reload(). :) – Deborah May 20 '16 at 08:43
  • 1
    You're right that the docs are pretty sparse for that function! – Michel Floyd May 20 '16 at 15:55

1 Answers1

5

In case anyone else comes here, this was solved with a great help from Hugh in the Meteor forum.

The solution did not use reload. Instead, it made use of Triggers in FlowRouter to check if the template was being reloaded, refresh it if so, and then stop once refreshed to prevent an endless loop.

Here is how it worked out.

// handle refreshing div on every load of div
let fireReload = false;

function reloadCheck(context, redirect, stop) {
  if (fireReload) {
    console.log('Hugh is Awesome and also reloading screen...');
    FlowRouter.reload();
    stop();
  }
}

function routeCleanup() {
  fireReload = !fireReload;
}

FlowRouter.route('/work', {
  action: function() {
        BlazeLayout.render( 'body-static', { 
            content:    'work',
        });
  }, 
  triggersEnter: [reloadCheck],
  triggersExit: [routeCleanup]
});
Deborah
  • 4,316
  • 8
  • 31
  • 45