From 6a95cf031ed089af035a14dc508eac99f70cee75 Mon Sep 17 00:00:00 2001 From: Esteban Abaroa Date: Wed, 31 Jan 2024 21:44:17 +0000 Subject: [PATCH] refactor: add android back button --- src/index.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index e11485ba..2665c903 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,6 +5,7 @@ import { HashRouter as Router } from 'react-router-dom'; import './lib/init-translations'; import './index.css'; import './themes.css'; +import { App as CapacitorApp } from '@capacitor/app'; const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); root.render( @@ -14,3 +15,12 @@ root.render( , ); + +// add back button in android app +CapacitorApp.addListener('backButton', ({ canGoBack }) => { + if (canGoBack) { + window.history.back(); + } else { + CapacitorApp.exitApp(); + } +});