Javascript (Angular) Listens for reload event; Tells local storage that a reload has occured then on new page load the if condition can redirect or run any other code.
this.redirectToIndexOnReload = () => {
if(localStorageService.get('reloaded') === true) {
localStorageService.set('reloaded', false);
//Redirect
$state.go('index');
//OR DO SOMETHING ELSE
}
};
this.notifyLocalStorageOfReload = () => {
$window.onbeforeunload = function(e) {
localStorageService.set('reloaded', true);
};
};
ServiceController = function($scope,OtherService) {
//Watch for Window Reload
OtherService.notifyLocalStorageOfReload();
//INITIALIZER
$scope.init = function () {
OtherService.redirectToIndexOnReload();
};
};