Cordova - routing not working in React Application

浪尽此生 提交于 2019-12-18 07:20:31

问题


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.

来源:https://stackoverflow.com/questions/53384887/cordova-routing-not-working-in-react-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!