[英]On android app built with Capacitor, error ERR_CONNECTION_REFUSED after redirect on local url
I'am developping a Vuejs project (vue 2.6.11) and I want to build an android app from it.我正在开发一个 Vuejs 项目(vue 2.6.11),我想从中构建一个 android 应用程序。 For that, I'am using capacitor: "@capacitor/android": "^3.4.0" and "@capacitor/core": "^3.4.0".
为此,我正在使用电容器:“@capacitor/android”:“^3.4.0”和“@capacitor/core”:“^3.4.0”。
The app is OK, I can run it with android studio but I've got an error in my login flow because of a web redirection: Following is the user journey:该应用程序没问题,我可以使用 android studio 运行它,但由于 web 重定向,我的登录流程出错:以下是用户旅程:
I expect my app to load the webpage that my vue rooter render at this URL '/login'.我希望我的应用程序能够加载我的 vue rooter 在此 URL '/login' 处呈现的网页。
This is my capacitor.config.json:这是我的电容器.config.json:
{
"appId": "com.XXX",
"appName": "XXXX",
"bundledWebRuntime": false,
"server": {
"allowNavigation": [
"SERVERURL"
],
"androidScheme": "https"
},
"webDir": "dist"
}
There are plenty topics on the web about ERR_CONNECTION_REFUSED error with capacitor but nothing seems relevant to my prolem. web 上有很多关于电容器 ERR_CONNECTION_REFUSED 错误的主题,但似乎与我的问题无关。
Thanking you,感谢您,
Jonath乔纳特
Try to change localhost
to your [local-ip-address]:[port]
or 10.0.2.2:[port]
.尝试将
localhost
更改为您的[local-ip-address]:[port]
或10.0.2.2:[port]
。
I'm not familiar in capacitor, but I've built my android app via flutter, and I found out that in android I need to use the ip 10.0.2.2
in my url. I'm not familiar in capacitor, but I've built my android app via flutter, and I found out that in android I need to use the ip
10.0.2.2
in my url.
I have achieved a workaround.我已经实现了解决方法。
I have used https://github.com/apache/cordova-plugin-inappbrowser
我用过
https://github.com/apache/cordova-plugin-inappbrowser
let ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes');
let myCallback = function (event: any) {
console.log('Updated URL: ', event.url);
// separate host form url
let host = event.url.split('/')[2];
// get pathName after host
let pathName = event.url.split(host)[1];
console.log('Path: ', pathName);
if (host === 'yourdomain.com') {
console.log('InAppBrowser closed');
ref.close();
setTimeout(() => {
this.$router.push(pathName);
}, 500);
}
}
ref.addEventListener('loadstart', myCallback);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.