Cordova-路由在React Application中不起作用 [英] Cordova - routing not working in React Application

查看:176
本文介绍了Cordova-路由在React Application中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的React应用程序,正在尝试将其移植到iOS和Android.

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

我设法在iOS上运行该应用程序,只是从常规路由更改为哈希路由.

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);

这种方法虽然不适用于Android.导航已损坏.

有什么建议吗?


上下文:

我要做的步骤是:

环境设置:

  • npm install -g cordova
  • 已安装的Java 8(不支持大于8的版本)
  • 已安装Android Studio
  • 已将JAVA_HOME,ANDROID_HOME和GRADLE_HOME添加到我的PATH中 —将模拟器添加到路径
  • 安装了正确的sdk执行程序:sdkmanager平台工具"平台; android-27"
  • 在Android Studio中添加了模拟器
  • 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准备和启动:

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.

推荐答案

如果您在项目中使用<Router>,请将其更改为<HashRouter>,否则将看到空白显示,因为屏幕上不会呈现任何内容.适用于iOS和Android.

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.

来源:

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

这篇关于Cordova-路由在React Application中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆