I have added 'VF Page' in lightning, I just want to refresh the whole page using javascript when event raised in VF page. I have used windw.location.reload(). But its not working.
1 Answer
You can use force:refreshView to force all data to reload, but the page itself still will not reload. This is because Lightning is meant to be a Single Page Application (SPA). Example code from the documentation is as follows:
refresh : function(component, event, helper) {
var action = cmp.get('c.myController');
action.setCallback(cmp,
function(response) {
var state = response.getState();
if (state === 'SUCCESS'){
$A.get('e.force:refreshView').fire();
} else {
//do something
}
}
);
$A.enqueueAction(action);
}
-
I just checked that "window.location.href" and "window.location.reload" return valid values inside a JS controller and when I call window.location.reload(true), the entire page gets refreshed. Not sure why the page will not reload as per your answer. Could you please elaborate? Commented Apr 11, 2018 at 13:13
-
@the_phantom force:refreshView is the recommended approach to "reload" Lightning. This eliminates the 1-3 second loading time. If you want to use location.reload, you can, but I'd advise against it unless you have no other way.– sfdcfox ♦Commented Apr 11, 2018 at 16:37