1

I have an existing React application and I'm trying to port it to iOS and Android.

I managed to run the application on iOS simply changing from regular routes to hash routes.

import { createBrowserHistory, createHashHistory } from 'history';
import { IS_HYBRID_APP, IS_PROD } from 'utils/environment';
export const history = window.cordova ? createHashHistory() : createBrowserHistory();
const connectRouterHistory = connectRouter(history);

This approach did not work on Android though. The navigation is broken.

Any advice?



CONTEXT:

The steps that I did are:

ENVIRONMENT SETUP:

  • npm install -g cordova
  • Installed Java 8 (versions greater than 8 are not supported)
  • Installed Android Studio
  • Added JAVA_HOME, ANDROID_HOME and GRADLE_HOME to my PATH — Added the emulator to the path
  • Installed the right sdk executing: sdkmanager “platform-tools” “platforms;android-27”
  • Added an emulator in Android Studio

APP PREP AND LAUNCH:

npm install
cordova platform add android
rm -rf www
react-app-rewired build
// vvv - injects the cordova script and the CSP meta tags into build/index.html
node config/hybrid-app-build.js
mv build www
cordova start android 

Same result both on emulator and on a real device. The routing does not work properly while everything else seems correctly in place.

Gabe
  • 5,997
  • 5
  • 46
  • 92
  • Can you please elaborate the behavior "The navigation is broken"? – BlackBeard Nov 20 '18 at 07:06
  • 1
    It seems like the navigation was actually fine. It wasn't immediate to realize that because the app was broken due to some missing backend data. I'll leave this question here as reference for other people trying to set up a React application using Cordova. – Gabe Nov 20 '18 at 20:09

1 Answers1

0

If you are using <Router> in your project change that to <HashRouter> otherwise you'll see a blank display as nothing will get rendered to the screen. Works for both iOS and Android.

Source:

https://stackoverflow.com/a/46785362/3850405

Ogglas
  • 62,132
  • 37
  • 328
  • 418