File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1- import { win } from '@utils/browser' ;
21import type { CloseWatcher } from '@utils/browser' ;
2+ import { win } from '@utils/browser' ;
33import { printIonError } from '@utils/logging' ;
44
55import { config } from '../global/config' ;
@@ -69,6 +69,21 @@ export const startHardwareBackButton = () => {
6969 } ) ;
7070 doc . dispatchEvent ( ev ) ;
7171
72+ /**
73+ * If no handlers have been registered, fall back to the default
74+ * behavior of navigating back in history. This ensures the hardware
75+ * back button works even when no router or custom handler is present.
76+ */
77+ if ( handlers . length === 0 ) {
78+ handlers . push ( {
79+ priority : FALLBACK_BACK_BUTTON_PRIORITY ,
80+ handler : ( ) => {
81+ win ?. history . back ( ) ;
82+ } ,
83+ id : index ++ ,
84+ } ) ;
85+ }
86+
7287 const executeAction = async ( handlerRegister : HandlerRegister | undefined ) => {
7388 try {
7489 if ( handlerRegister ?. handler ) {
@@ -138,3 +153,4 @@ export const startHardwareBackButton = () => {
138153
139154export const OVERLAY_BACK_BUTTON_PRIORITY = 100 ;
140155export const MENU_BACK_BUTTON_PRIORITY = 99 ; // 1 less than overlay priority since menu is displayed behind overlays
156+ const FALLBACK_BACK_BUTTON_PRIORITY = - 1 ; // Fallback when no other handlers are registered
You can’t perform that action at this time.
0 commit comments