mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
26 lines
705 B
TypeScript
26 lines
705 B
TypeScript
import { Injectable, Directive } from '@angular/core'
|
|
import { CanDeactivate } from '@angular/router'
|
|
import { HostListener } from '@angular/core'
|
|
|
|
@Directive()
|
|
export abstract class PageCanDeactivate {
|
|
abstract canDeactivate (): boolean
|
|
|
|
@HostListener('window:beforeunload', ['$event'])
|
|
unloadNotification (e: any) {
|
|
console.log(e)
|
|
if (!this.canDeactivate()) {
|
|
e.returnValue = true
|
|
}
|
|
}
|
|
}
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class CanDeactivateGuard implements CanDeactivate<PageCanDeactivate> {
|
|
|
|
canDeactivate (page: PageCanDeactivate): boolean {
|
|
return page.canDeactivate() || confirm('You have unsaved changes. Are you sure you want to leave the page?')
|
|
}
|
|
} |