IONIC项目内config.xml中错误页面html文件的位置,在脱机/无网络连接时使用,以显示错误消息

时间:2018-12-17 17:45:33

标签: cordova ionic-framework ionic2 ionic3

我们正在为企业产品开发Ionic应用程序。 项目中使用的所有数据/内容/ Web资产都是从S3之类的远程位置加载的。

在config.xml中,例如,index.html的路径可以像这样

因此,我们需要处理“无网络/互联网”情况。

config.xml具有选项“ ErrorUrl”,该选项应指向errorPage.html。

我的问题是,

在IONIC项目中,此错误html页应位于何处,其路径应位于config.xml中??

以下是我已浏览但未获得任何具体答案的参考链接,

https://cordova.apache.org/docs/en/latest/config_ref/#preference (搜索ErrorUrl属性)

https://www.raymondcamden.com/2013/02/19/Some-examples-of-Android-PhoneGap-Config-Settings

请帮助我!

预先感谢:slight_smile:

1 个答案:

答案 0 :(得分:0)

使用Ionic,您可以使用Network plugin处理网络连接错误。

安装

在您的Ionic项目文件夹中运行这些命令

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.johnDoe.storeapp"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

设置

您需要将插件添加到ionic cordova plugin add cordova-plugin-network-information npm install --save @ionic-native/network 文件中的应用模块中:

app.module.ts

使用

您可以使用以下功能轻松捕获网络变化:

import { Network } from '@ionic-native/network';

@NgModule({
  providers: [
    Network
  ]
})