0
<SafeAreaView>
      <NativeRouter>
        <Routes>
          <Route path="/" element={<Main/>}/>
          <Route path="one" element={<One/>}/>
          <Route path="second" element={<Second/>}/>
        </Routes>
      </NativeRouter>
</SafeAreaView>

This is the router structure created using react-router-native. This app closes when you press the back button on Android.

Is it possible to make the app go to the previous router without exiting when the back button of the android hardware is pressed?

I found a function called useAndroidBackButton in react-router-native v6, but I don't know how to use it.

extradeck
  • 366
  • 1
  • 5
  • 19
  • 1
    It doesn't quite seem that `useHardwareBackButton` is completely implemented [just yet](https://github.com/remix-run/react-router/blob/8f63699bac4006294619a4c1fb317aba515b09b7/packages/react-router-native/index.tsx#L189-L198). Are you saying the Android back button isn't navigating back through the history when it's pressed? – Drew Reese Dec 14 '21 at 05:07
  • @DrewReese Yes. The app closes when the back button is pressed. It has not been implemented yet, I'll have to implement it myself or wait for an update. – extradeck Dec 14 '21 at 05:23
  • Well, I was asking if back navigation was working at all, from any pages/routes navigated to. It's common for the android back button to close the app if you're already on the home page and there's not a page/history to go back to. – Drew Reese Dec 14 '21 at 05:42
  • I used `navigate('one')` in the same way. The app is closed when the hardware back button is pressed even on the moved page. Because `navitage(-1)` worked in the NavBar part that I implemented myself, I thought that the index was being recorded normally. – extradeck Dec 14 '21 at 05:53

0 Answers0