2017-11-18 242 views
-2

現在我有Ionic3,Angular4 Android應用工作。每當我回到上一頁時,它都會在Android應用程序中重新加載頁面。如何防止這一點。該頁面仍然已加載。所以我不想重裝一遍又一遍當我們回到上一頁時,如何防止重新加載頁面?

+0

向我們展示一些代碼。重裝是什麼意思? –

回答

0

使用Push和離子的框架,可以作爲新的頁面推入和彈出的,對應於歷史向前和向後移動一個簡單的棧中彈出。

Refer Ionic documentation too

@Component({ 
    template: ` 
    <ion-header> 
    <ion-navbar> 
     <ion-title>Login</ion-title> 
    </ion-navbar> 
    </ion-header> 

    <ion-content> 
    <button (click)="goToOtherPage()"> 
     Go to OtherPage 
    </button> 
    </ion-content>` 
}) 
export class StartPage { 
    constructor(public navCtrl: NavController) {} 

    goToOtherPage() { 
    //push another page onto the history stack 
    //causing the nav controller to animate the new page in 
    this.navCtrl.push(OtherPage); 
    } 
} 

@Component({ 
    template: ` 
    <ion-header> 
    <ion-navbar> 
     <ion-title>Other Page</ion-title> 
    </ion-navbar> 
    </ion-header> 

    <ion-content>I'm the other page!</ion-content>` 
}) 
class OtherPage {} 
0

使用this.navCtrl.push(Page);代替this.navCtrl.setRoot(Page);並記得做

ionViewWillEnter() { 
    this.viewCtrl.showBackButton(true) 
} 

goBackToPreviousPage() { 
    this.navCtrl.pop(); 
} 
相關問題