File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/platform/plugins/shared/workflows_management/public/shared/ui Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,20 @@ export const UnsavedChangesPrompt: React.FC<Props> = ({
2727 currentPathRef . current = location . pathname ;
2828 } , [ location . pathname ] ) ;
2929
30+ useEffect ( ( ) => {
31+ const handler = ( event : BeforeUnloadEvent ) => {
32+ if ( hasUnsavedChanges ) {
33+ // These 2 lines of code are the recommendation from MDN for triggering a browser prompt for confirming
34+ // whether or not a user wants to leave the current site.
35+ event . preventDefault ( ) ;
36+ event . returnValue = '' ;
37+ }
38+ } ;
39+ // Adding this handler will prompt users if they are navigating to a new page, outside of the Kibana SPA
40+ window . addEventListener ( 'beforeunload' , handler ) ;
41+ return ( ) => window . removeEventListener ( 'beforeunload' , handler ) ;
42+ } , [ hasUnsavedChanges ] ) ;
43+
3044 const message = ( nextLocation : any ) => {
3145 const nextPath : string | undefined = nextLocation ?. pathname ;
3246 const currentPath = currentPathRef . current ;
You can’t perform that action at this time.
0 commit comments