Cordova - routing not working in React Application
up vote
1
down vote
favorite
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.
android reactjs cordova mobile hybrid-mobile-app
add a comment |
up vote
1
down vote
favorite
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.
android reactjs cordova mobile hybrid-mobile-app
Can you please elaborate the behavior "The navigation is broken"?
– BlackBeard
Nov 20 at 7:06
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.
– Ga Sacchi
Nov 20 at 20:09
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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.
android reactjs cordova mobile hybrid-mobile-app
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.
android reactjs cordova mobile hybrid-mobile-app
android reactjs cordova mobile hybrid-mobile-app
edited Nov 20 at 2:37
asked Nov 20 at 1:16
Ga Sacchi
2,25722044
2,25722044
Can you please elaborate the behavior "The navigation is broken"?
– BlackBeard
Nov 20 at 7:06
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.
– Ga Sacchi
Nov 20 at 20:09
add a comment |
Can you please elaborate the behavior "The navigation is broken"?
– BlackBeard
Nov 20 at 7:06
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.
– Ga Sacchi
Nov 20 at 20:09
Can you please elaborate the behavior "The navigation is broken"?
– BlackBeard
Nov 20 at 7:06
Can you please elaborate the behavior "The navigation is broken"?
– BlackBeard
Nov 20 at 7:06
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.
– Ga Sacchi
Nov 20 at 20:09
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.
– Ga Sacchi
Nov 20 at 20:09
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384887%2fcordova-routing-not-working-in-react-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you please elaborate the behavior "The navigation is broken"?
– BlackBeard
Nov 20 at 7:06
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.
– Ga Sacchi
Nov 20 at 20:09