[SOLVED] How to force a refresh on Meteor frontend?

I’m having a problem with our app where after creating some crucial docs on the backend (not via pub/sub) the Frontend needs to be forced to do a refresh.

How can I achieve this in the template? I’m trying in the onRendered function of that template but Windows.location.reload() is throwing an error:

TypeError: Cannot read property 'reload' of undefined

Here’s the code:

Template.onboarding1.onRendered(function () {
    Window.location.reload();
});

I’m a backend Dev so please excuse if this is a rather basic question for your guys.

Thanks in advance,

Andreas

Use location.reload(); on page load, or if using React router use a Redirect component, if you want to keep it all in React jsx

A simple way would be to just set a variable that gets passed to the client reload = true then have a conditional that checks if(reload) location.reload(); in the markup and badabing you got it

1 Like

Thank you @truedon - I managed to solve it by adding it to the onDestroyed function. When I put it in the onRendered function the screen constantly flickered as it was called over and over.

A new thing learned for me. Thanks again!

1 Like

awesome man and you’re welcome!