我是离子3的新手,我正在导航一个页面到另一个页面,导航我使用this.navCtrl.setRoot(RegistrationPage)并在应用程序启动后我将根页面设置为登录页面。当我进入一些dashbaord页面和菜单项目时我有注销按钮,点击注销我再次设置rootpage一个登录页面,但在这里我得到错误。
从Ionic 2 Error of X page is part of the declarations of 2 modules
复制的图片我面临同样的问题,但答案对我没有帮助
app.mudule.js
//Pages
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
import { UserdashboardPage } from
'../pages/userdashboard/userdashboard';
import { ManagerdashboardPage } from
'../pages/managerdashboard/managerdashboard';
import { RegistrationPage } from '../pages/registration/registration';
import { ModalViewPage } from '../pages/modal-view/modal-view';
import { ReRegistrationPage } from '../pages/re-registration/re-
registration';
@NgModule({
declarations: [
MyApp,
HomePage,
LoginPage,
UserdashboardPage,
ManagerdashboardPage,
RegistrationPage,
ModalViewPage,
ReRegistrationPage
],
imports: [
BrowserModule,
HttpClientModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot(),
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
LoginPage,
UserdashboardPage,
ManagerdashboardPage,
RegistrationPage,
ModalViewPage,
ReRegistrationPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
HttpModule,
HttpClientModule,
LoginServiceProvider,
Device,
AlertServiceProvider,
LanguageConversionProvider,
FCM,
Network,
NetworkconnectivityProvider,
Constants
]
})
export class AppModule {}
export function HttpLoaderFactory(http: HttpClient) {
/ /return new TranslateHttpLoader(http);
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
app.component.js
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Storage } from '@ionic/storage';
import { Device } from '@ionic-native/device';
import { FCM } from '@ionic-native/fcm';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
import { UserdashboardPage } from
'../pages/userdashboard/userdashboard';
import { RegistrationPage } from '../pages/registration/registration';
import { ReRegistrationPage } from '../pages/re-registration/re-
registration';
import { NetworkconnectivityProvider } from
'../providers/networkconnectivity/networkconnectivity';
import { AlertServiceProvider } from '../providers/alert-service/alert-
service';
import { TranslateService } from '@ngx-translate/core';
import { LanguageConversionProvider } from '../providers/language-
conversion/language-conversion';
export interface MenuItem {
title: string;
component: any;
icon: string;
}
@Component({
templateUrl: 'app.html'
})
export class MyApp {
public rootPage;
pages: any = [];
appMenuItems: Array<MenuItem>;
@ViewChild(Nav) nav: Nav;
constructor(platform: Platform ...) {
this.appMenuItems = [
{ title: 'Home', component: UserdashboardPage, icon: 'home' },
{ title: 'Device Registration', component: ReRegistrationPage, icon: 'people' },
{ title: 'About', component: '', icon: 'information-circle' },
{ title: 'Logout', component: 'LoginPage', icon: 'log-out' },
];
platform.ready().then(() => {
console.log("Device ready event fired platform this.device.platform -- " + this.device.platform);
statusBar.styleDefault();
splashScreen.hide();
translateService.setDefaultLang('en');
translateService.use('en');
//FCM registration and on receive notifications code
if (this.networkCheck.isOnline) {
fcm.subscribeToTopic('marketing');
fcm.getToken().then(token => {
//backend.registerToken(token);
console.log("FCM token -- " + token);
if (token == '' || token == null || token == undefined) {
this.showAlertService.showAlert(this.langConvService.convertLang('Err_Invalid_Access_Title'), this.langConvService.convertLang('Err_Token_Txt'), this.langConvService.convertLang('Ok'));
return false;
}
this.storage.set('fcmToken', token);
}).catch(error => {
this.showAlertService.showAlert(this.langConvService.convertLang('Err_Invalid_Access_Title'), this.langConvService.convertLang('Err_Token_Txt'), this.langConvService.convertLang('Ok'));
console.log("getToken() FCM token -- ", JSON.stringify(error))
});
} else {
console.log("Device is offline")
this.showAlertService.showAlert(this.langConvService.convertLang('Err_Nw_Title'), this.langConvService.convertLang('Err_Nw_Txt'), this.langConvService.convertLang('Ok'));
}
fcm.onNotification().subscribe(data => {
if (data.wasTapped) {
console.log("Received in background");
} else {
console.log("Received in foreground");
};
})
fcm.onTokenRefresh().subscribe(token => {
//backend.registerToken(token);
console.log("onTokenRefresh() tokentokenv -- " + token);
})
//judging login or home page
this.storage.get('loginStatus').then(loggedIn => {
console.log("loggedIn -- ", loggedIn)
this.rootPage = loggedIn ? UserdashboardPage : LoginPage;
});
});
}
openPage(page, event) {
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
if(page.component == "LoginPage"){
console.log("Logout button clicked");
// this.nav.pop();
// this.nav.pop();
this.nav.setRoot(page.component);
this.storage.clear();
}else{
this.nav.setRoot(page.component);
}
event.preventDefault();
event.stopPropagation();
} }
Login.module.ts
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { LoginPage } from './login';
@NgModule({
declarations: [
LoginPage,
],
imports: [
IonicPageModule.forChild(LoginPage),
],
})
export class LoginPageModule {}