Vue NativeVue Native
Guide
Components
Composables
Navigation
Architecture
  • iOS
  • Android
  • macOS
GitHub
Guide
Components
Composables
Navigation
Architecture
  • iOS
  • Android
  • macOS
GitHub
  • Device & System

    • useNetwork
    • useAppState
    • useColorScheme
    • useDeviceInfo
    • useBattery
    • useDimensions
    • usePlatform
  • Storage & Files

    • useAsyncStorage
    • useSecureStorage
    • useFileSystem
    • useDatabase
  • Sensors & Hardware

    • useGeolocation
    • useBiometry
    • useHaptics
    • useSensors
    • useBluetooth
  • Media

    • useCamera
    • useImagePicker
    • useAudio
    • useCalendar
    • useContacts
  • Networking

    • useHttp
    • useWebSocket
  • Permissions

    • usePermissions
  • Navigation

    • useBackHandler
    • useSharedElementTransition
  • UI

    • useKeyboard
    • useClipboard
    • useAccessibility
    • useShare
    • useLinking
    • useAnimation
    • useGesture
    • useTeleport
    • useNotifications
    • useI18n
    • usePerformance
    • useInspector
  • Authentication

    • useAppleSignIn
    • useGoogleSignIn
  • Monetization & Updates

    • useIAP
    • useOTAUpdate
    • useBackgroundTask
  • Desktop (macOS)

    • useWindow
    • useMenu
    • useFileDialog
    • useDragDrop

useBackHandler

Intercept the hardware back button press on Android. On iOS this is a no-op (no hardware back button), but the event can still be dispatched programmatically.

Usage

<script setup>
import { ref } from '@thelacanians/vue-native-runtime'
import { useBackHandler } from '@thelacanians/vue-native-runtime'

const hasUnsavedChanges = ref(false)

useBackHandler(() => {
  if (hasUnsavedChanges.value) {
    // Show discard dialog; do not call BackHandler.exitApp
    return true
  }
  // This listener did not handle the press — useBackHandler calls exitApp
  return false
})
</script>

API

useBackHandler(handler: () => boolean): void

Parameters

ParameterTypeDescription
handler() => booleanCalled on hardware back press. Return true if this listener handled the press (useBackHandler will not call exitApp). Return false to let this composable exit the app.

Platform Support

PlatformSupport
AndroidHardware back button
iOSNo-op (no hardware back button)

Notes

  • The handler is automatically registered on onMounted and cleaned up on onUnmounted.
  • Returning true only skips exitApp from this composable. The bridge still delivers hardware:backPress to every subscriber, including a router created with handleBackButton: true. Do not combine the two on the same screen.
  • If no handler is registered and handleBackButton is off, Android finishes the current Activity.
  • If multiple components register handlers, each mounted handler receives the event. Prefer one owner for modal or navigation back behavior.
Edit this page
Last Updated: 8/18/26, 6:40 AM
Contributors: github-actions[bot], Abdul Hamid
Next
useSharedElementTransition