feat(vue): add hook to access Ionic Vue router (#22072)

This commit is contained in:
Liam DeBeasi
2020-09-11 11:33:41 -04:00
committed by GitHub
parent 8227844cbc
commit 3d34b68fbd
2 changed files with 14 additions and 1 deletions

25
packages/vue/src/hooks.ts Normal file
View File

@ -0,0 +1,25 @@
import { BackButtonEvent } from '@ionic/core';
import { inject } from 'vue';
type Handler = (processNextHandler: () => void) => Promise<any> | void | null;
export interface IonRouter {
canGoBack: (deep: number) => boolean;
}
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 };
}
export const useIonRouter = (): IonRouter => {
const { canGoBack } = inject('navManager') as any;
return {
canGoBack
} as IonRouter
}