Cordova - routing not working in React Application












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.










share|improve this question

























  • Can you please elaborate the behavior "The navigation is broken"?

    – BlackBeard
    Nov 20 '18 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 '18 at 20:09
















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.










share|improve this question

























  • Can you please elaborate the behavior "The navigation is broken"?

    – BlackBeard
    Nov 20 '18 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 '18 at 20:09














1












1








1


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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 2:37







Ga Sacchi

















asked Nov 20 '18 at 1:16









Ga SacchiGa Sacchi

2,36922244




2,36922244













  • Can you please elaborate the behavior "The navigation is broken"?

    – BlackBeard
    Nov 20 '18 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 '18 at 20:09



















  • Can you please elaborate the behavior "The navigation is broken"?

    – BlackBeard
    Nov 20 '18 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 '18 at 20:09

















Can you please elaborate the behavior "The navigation is broken"?

– BlackBeard
Nov 20 '18 at 7:06







Can you please elaborate the behavior "The navigation is broken"?

– BlackBeard
Nov 20 '18 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 '18 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 '18 at 20:09












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?