I am building the Angular Router Tutorial Application using Ionic 4 in preparation of a real world project build in Ionic 4.
So far I could find workarounds for every problem I encountered, but now I am stuck:
The latest part of the tutorial was adding a dialog, which asks the user, if she really wanna leave.
As I deploy the app to mobile devices too, naturally I wanted to use @ionic-native/dialogs for that.
First problem, after the manual version selection of the newest beta: ionic serve does not work anymore, as Dialogs cannot find cordova.
This is fine, I add the browser platform to cordova and instead of ionic serve I use ionic cordova emulate browser or ionic cordova run browser. As expected, the dialogs are now working, but something strange happened: The URL navigation broke!
As Ionic 4 now uses the angular router, one navigates the app via URL changes. This is create for e.g. sharing an URL and one can directly type an URL into the address bar and navigate to it. This worked fine with ionic serve, I could directly navigate into a sub-url. Using ionic cordova run browser shows an 404 error if using a sub-url directly (and the error page is generic, not the one defined in the app). Accessing the app only works via the root-route.
Another strange think is that when I navigate the app, the url changes accordingly, but doing a F5 refresh yields again the generic 404 error page. Please look at the gifs for a visual representation.
Thanks for your reply.
As I stated in my post, I want to use cordova-plugins/ionic-native, in this case the dialogs plugin, as I want to publish to mobile devices too.
So I have to use cordova browser for browser deployment, else cordova is not available in the browser (obviously) and the dialogs code throws at runtime.
I know that I can work around that by checking platforms in my code and not use cordova in the browser at all, but well, that is why I am using cordova, I shouldnāt be the one checking the platform, it should ājust workā, as long as the plugin supports the platforms.
That is why I was asking for a fix, I am aware that I can work around that (i.e. not using cordova in the browser and do explicit platform checking in code), but I believe this not to be the fix.
EDIT: Of course, in this case I could ditch the dialogs plugin and use e.g. window.confirm(), but this is more of a case study of Ionic, there are bound to be native plugins I would not be able to ditch in the real project.
Looks like youāve figured out your problem, but for future reference using Cordova browser builds isnāt recommended by Ionic. If youāre looking for an approach where you donāt have to worry about using platform checks and just having the code work where the functionality is available, you might prefer to use Ionicās Capacitor instead. It is still in beta, but the general idea is that all the APIs will have a web implementation where the functionality is available and fail gracefully if it isnāt available.
Just tried that today, as it sounded pretty cool.
Unfortunately, could not get an android build to run, after several hiccups it did finally build in Android Studio and started on the device, but after the (capacitor) splashscreen I was welcomed with a Connection refused to localhost:7516 message and gave up on this project.
For the production project, I think we will go with cordova and explicit platform checks for now, as this seems the most reliable.
Would love to pick up capacitor in the future though (as a PWA is part of the roadmap), a cordova to capicator guide, when capacitor is more stable, would be awesome by that time!
Yeah although there isnāt too much required in moving from Cordova to Capacitor, I think a transition guide would definitely be useful (Iāve been considering writing one).
There might be some difficulties in in switching to Capacitor if you arenāt familiar with how it works, but even though it is in beta it is very stable today and I think there is already quite a few people already using it in production (Iāve been using it for many months with no real issues). Ionic have said itāll be out of beta soon, but there is very little that is going to be changing as itās mostly already there.
Well, this sounds promising. Do you have any idea where my error could come from?
I removed all cordova platforms from my package.json (via ionic cordova platform rm) and plugins from my code, added capacitor according to the guide, build and then synced.
I did notice that it uses the (cordova) www folder by default, is this correct?
Yes, by default the www folder is used so you should be able to run ionic build --prod or npm run build:prod (depending on the version you are using) to create the build.
Iāve never tried transitioning from a Cordova to a Capacitor project before (as in, adding Capacitor to the same project rather than starting a new project with Capacitor) so Iām not 100% sure on all the places where you might get stuck. It is worth noting that although most Cordova plugins will work with Capacitor, not all of them will. The Splash Screen plugin for example causes conflicts with Capacitor and needs to be removed.
This is why a Cordova -> Capacitor guide might be interesting, because Iām sure there are at least a few things Iām not thinking of that could trip people up.
Thanks. I am facing the same issue. Capacitor seems to have some limitations around browser support for Cordova plugins. @joshmorony, could you please suggest some workaround.
Hi, So I was reading all the comments here and I found my self still in this mess. The routing doesnāt seem to work even when I provided the following code as some of you said:
{ provide: LocationStrategy, useClass: HashLocationStrategy }
Did anyone find a solution till now because at the moment I have tabs in my application and they are working fine, but once I click on an item link to route me to a page, the page doesnt show up, basically i am still in the same problem.