我正在使用angular,需要将以下内容放入一个配置变量中,放入我的一个配置文件中,但是我对它们的工作方式不太熟悉。任何建议都会有所帮助!
export interface ComponentCanDeactivate {
canDeactivate: () => boolean | Observable<boolean>;
}
@Injectable()
export class PreNavigationGuard implements CanDeactivate<ComponentCanDeactivate> {
canDeactivate(component: ComponentCanDeactivate): boolean | Observable<boolean> {
// if there are no pending changes, just allow deactivation; else confirm first
return component.canDeactivate() ?
true :
// NOTE: this warning message will only be shown when navigating elsewhere within app;
// when navigating away from angular app, the browser will show a generic warning message
confirm('WARNING: You have unsaved changes. Press Cancel to go back and save these changes, or OK to lose these changes.');
}
}