mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 15:07:13 +08:00
feat(vue): add hardware back button hook (#22069)
This commit is contained in:
12
packages/vue/src/hardware-back-button.ts
Normal file
12
packages/vue/src/hardware-back-button.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { BackButtonEvent } from '@ionic/core';
|
||||
|
||||
type Handler = (processNextHandler: () => void) => Promise<any> | void | null;
|
||||
|
||||
export const useHardwareBackButton = (priority: number, handler: Handler) => {
|
||||
const callback = (ev: BackButtonEvent) => ev.detail.register(priority, handler);
|
||||
const unregister = () => document.removeEventListener('ionBackButton', callback);
|
||||
|
||||
document.addEventListener('ionBackButton', callback);
|
||||
|
||||
return { unregister };
|
||||
}
|
||||
@ -11,6 +11,8 @@ export { IonTabButton } from './components/IonTabButton';
|
||||
export { IonTabs } from './components/IonTabs';
|
||||
export { IonTabBar } from './components/IonTabBar';
|
||||
|
||||
export { useHardwareBackButton } from './hardware-back-button';
|
||||
|
||||
export {
|
||||
// Overlay Controllers
|
||||
alertController,
|
||||
|
||||
Reference in New Issue
Block a user