You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
content: Missing Event type when trying to subscribe to 'ionBackButton' with React. #4261
When trying to subscribe to 'ionBackButton' the way it is written on the docs, the compiler complains about the property detail with the message: "Property 'detail' does not exist on type 'Event'.ts(2339)".
The current solution is to cast the event parameter to any. Other solutions have been tried, like casting to BackButtonEvent from @ionic/react or @ionic/core.
Image below is how I found the current solution on the Ionic discord:
import{App}from"@capacitor/app";import{BackButtonEventDetail}from"@ionic/core";import{useEffect}from"react";import{useOptimizedIonRouter}from"#/helpers/useOptimizedIonRouter";exportdefaultfunctionAndroidBackButton(){constrouter=useOptimizedIonRouter();// Back button handling for Android native appuseEffect(()=>{constbackButtonHandler=(ev: CustomEvent<BackButtonEventDetail>)=>{ev.detail.register(-1,()=>{// pswp is the gallery component. It pushes state, but the router isn't aware.// So if that's open, don't close the app just yetif(!router.canGoBack()&&!document.querySelector(".pswp--open")){App.exitApp();}});};document.addEventListener("ionBackButton",backButtonHandlerasEventListener,);return()=>{document.removeEventListener("ionBackButton",backButtonHandlerasEventListener,);};},[router]);returnnull;}
Activity
aeharding commentedon Aug 26, 2025
CustomEvent<BackButtonEventDetail>is the param: