两天前我提出了一个类似的问题,但这次我在实际设备或模拟器中运行代码时遇到了同样的错误。在常规浏览器上,它可以正常工作。
这是我的app.component.ts代码:
import { Component, ViewChild } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
import {NativeStorage} from '@ionic-native/native-storage';
import { NavController } from 'ionic-angular';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = LoginPage;
@ViewChild('navApp') nav : NavController;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private nativeStorage: NativeStorage,) {
platform.ready().then(() => {
this.nativeStorage.getItem('userExists').then((data)=>{
this.nav.push(HomePage);
console.log(data.userExists);
},(error)=>{
console.log("No Data in Local Storage");
this.nav.push(LoginPage);
})
statusBar.styleDefault();
splashScreen.hide();
});
}
}
这是我的app.html
<ion-nav #navApp [root]="rootPage"></ion-nav>
这是我的版本信息
global packages:
@ionic/cli-utils : 1.2.0
Cordova CLI : 7.0.1
Ionic CLI : 3.2.0
local packages:
@ionic/app-scripts : 1.3.7
@ionic/cli-plugin-cordova : 1.2.1
@ionic/cli-plugin-ionic-angular : 1.2.0
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.2.1
System:
Node : v6.10.2
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
的package.json:
{
"name": "myapp",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.1.0",
"@angular/compiler": "4.1.0",
"@angular/compiler-cli": "4.1.0",
"@angular/core": "4.1.0",
"@angular/forms": "4.1.0",
"@angular/http": "4.1.0",
"@angular/platform-browser": "4.1.0",
"@angular/platform-browser-dynamic": "4.1.0",
"@ionic-native/core": "3.7.0",
"@ionic-native/facebook": "^3.10.2",
"@ionic-native/native-storage": "^3.10.3",
"@ionic-native/splash-screen": "3.7.0",
"@ionic-native/status-bar": "3.7.0",
"@ionic/storage": "2.0.1",
"cordova-android": "^6.2.3",
"cordova-plugin-console": "^1.0.5",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-facebook4": "^1.9.0",
"cordova-plugin-nativestorage": "^2.2.2",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.2",
"cordova-plugin-whitelist": "^1.3.1",
"ionic-angular": "3.2.1",
"ionic-native": "^2.5.1",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"rxjs": "5.1.1",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.10"
},
"devDependencies": {
"@ionic/app-scripts": "1.3.7",
"@ionic/cli-plugin-cordova": "^1.2.1",
"@ionic/cli-plugin-ionic-angular": "^1.2.0",
"typescript": "2.2.1"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"cordova-plugin-facebook4": {
"APP_ID": "305938313175123",
"APP_NAME": "myapp"
},
"cordova-plugin-nativestorage": {}
},
"platforms": [
"android"
]
}
}
答案 0 :(得分:1)
更新到最新的离子释放3.3.0解决了这个问题!
答案 1 :(得分:0)
为什么不改变rootPage的值而不是推送?
你有变量
rootPage:any = LoginPage;
因此,默认情况下,您的主页将是LoginPage。当您在本地存储区中检查昵称是否存在时,请使用
而不是推送页面this.rootPage = NameofYourPageHere.
这应该有效。