mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-04 03:03:18 -05:00 
			
		
		
		
	Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
		
			
				
	
	
		
			21 lines
		
	
	
		
			535 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			535 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
export function useNavigationWarning() {
 | 
						|
  return { activateNavigationWarning, deactivateNavigationWarning };
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Displays a warning before the user navigates to another page
 | 
						|
 * e.g., by clicking a link (which isn't internal and rendered without page load),
 | 
						|
 * reloading the page,
 | 
						|
 * or closing the tab.
 | 
						|
 */
 | 
						|
const activateNavigationWarning = () => {
 | 
						|
  window.onbeforeunload = () => true;
 | 
						|
};
 | 
						|
 | 
						|
/**
 | 
						|
 * Disables the warning when navigating to a page
 | 
						|
 */
 | 
						|
const deactivateNavigationWarning = () => {
 | 
						|
  window.onbeforeunload = null;
 | 
						|
};
 |