question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If hostname set, cannot navigate certain app's url - it tries to open the remote one

See original GitHub issue

Bug Report

Problem

I set preference name="hostname" value="site.com" /> and I trying to navigate

What is expected to happen?

window.location.href = 'https://site.com';

should open corresponding application URL.

And:

window.location.href = 'https://site.com/page';

should open corresponding application URL, too.

What does actually happen?

First one works, but second one doesn’t. It tries to open remote URL with same host. And, it opens that URL in Cordova’s webview, not in external browser…

Information

<?xml version='1.0' encoding='utf-8'?>
<widget id="gls.messenger" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Hello World</name>
    <description>Sample Apache Cordova App</description>
    <author email="dev@cordova.apache.org" href="https://cordova.apache.org">
        Apache Cordova Team
    </author>
    <content src="/" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <preference name="hostname" value="site.com" />
</widget>

Command or Code

See above.

Environment, Platform, Device

Android.

Version information

cordova 11.0.0 cordova-android 10.1.2

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
breautekcommented, May 18, 2022

For Cordova specific frameworks we have

Ionic / Angular / React (Framework for Cordova) uses hash based routing by default.

For non-cordova specific frameworks we have the common:

react-router that provides a Hash strategy. It does state it shouldn’t be used unless necessary because they are thinking in the context of where URLs are seen in traditional web applications, where unclean URLs effects SEO. It doesn’t have a default routing strategy, you have to declare it.

I’m less familiar with svelte but one of the recommended packages I saw was svelte-spa-router which uses hash based routing by default.

Hashes are just unfamiliar for any web developer in current decade.

So I don’t really think has it’s place.

Hashes are definitely obsolete for traditional web development, especially for any system that is sensitive to SEO, which Cordova applications are not.

Part of my push-back is because this was something that was discussed previously in https://github.com/apache/cordova-android/pull/1137 Adding the flag as suggested to redirect to the html file on not found files I think would fall into the same category.

I will develop my own plugin (or some other architecture) which will solve the problem…

If you truely need clean URLs for your cordova application, then this would be your path forward. But I’ve already listed above that all modern frameworks have a hash-based strategy available, either built-in, or as a third-party library. Abstractions can easily be made so that the cordova applications uses hash-based routing while your web portal uses clean urls.

If you think Cordova should reconsider this stance, then I’d suggest opening a thread on our Dev Mailing List, so other project members can pitch in.

2reactions
breautekcommented, May 18, 2022

What is the actual use case for having clean URLs in a cordova application where URLs are never shown to the user?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to resolve host "<URL here>" No address associated ...
In my Android application for reading RSS links, I am getting this error: java.net.UnknownHostException: Unable to resolve host "example.com"; No address ...
Read more >
Troubleshoot Azure Active Directory Application Proxy
Covers how to troubleshoot errors in Azure Active Directory Application Proxy.
Read more >
How to fix 8 common remote desktop connection problems
Click System and Security. Click Windows Defender Firewall. Click Allow an App or Feature Through Windows Defender Firewall. Select the Remote ...
Read more >
Remote Desktop can't connect to the remote computer - 4sysops
This post aims to discuss all the common reasons why a Remote Desktop Protocol (RDP) connection can't connect to a remote computer.
Read more >
Set Chrome app and extension policies (Windows)
Then, if you want to customize policies for specific apps or extensions, you can override your defaults. Step 1: Review the policy. Policy,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found