React Ionic 4 hardware back button and keyboard Go button

Does anyone has example of how hardware back button and keyboard Go button should be implemented in React Ionic?

Hello,
I don’t think so people will give you ready made example. So better for you try your self and check result what you getting an success or error. Then share a sample of your code. That way might be people will help you.

I have found solution for hardware Back button, but for keyboard Go button I just don’t have any idea how this should be implemented at all because I couldn’t find any example.

To exit app after click back button on hardware, first you have to prevent default history back.

// App component
import { setupConfig } from '@ionic/react'

setupConfig({
  hardwareBackButton: false
})

then add Listener back-button

https://capacitor.ionicframework.com/docs/apis/app#method-addListener-3

import { Plugins, Capacitor } from '@capacitor/core'

  ...

  useEffect(() => {
    if (Capacitor.isNative) {
      Plugins.App.addListener('backButton', e => {
        if (history.location.pathname === '/') {
          Plugins.App.exitApp()
        } else if (history.location.pathname === '/detail') {
          history.push('/')
        } else {
          history.goBack()
        }
      })
    }
  }, []) // eslint-disable-line
...