簡體   English   中英

Ionic2:以root身份設置當前頁面

[英]Ionic2: Set as root the current page

在嘗試驗證某些內容后,我嘗試將root設置為root,在這種情況下,啟動服務后因為一旦啟動,用戶無法返回上一頁,直到完成當前頁面但是如果用戶尚未啟動服務然后他仍然可以回到前一個。

所以,你知道怎么做嗎?

謝謝!

如果您已經在該頁面上,則可以使用Nav Guards ,而不是將其設置為Root

在某些情況下,開發人員應該能夠控制離開和進入的視圖。 為了實現這一點,NavController具有ionViewCanEnter和ionViewCanLeave方法。 類似於Angular 2路線防護,但與NavController更加集成。

因此,我們可以檢查服務是否已經啟動但尚未完成,並阻止用戶離開頁面,直到服務完成。

為此,我們可以這樣做:

    // Method that gets executed when the user tries to leave the page
    ionViewCanLeave() {
        if(this.serviceHasStarted && !this.serviceHasFinished) {
            let showAlertMessage = this.alertCtrl.create({
                title: 'Error',
                message: '¿You can\'t leave the page until ...',
                buttons: [
                {
                    text: 'Ok',
                    handler: () => {

                    }
                }]
            });

            showAlertMessage.present();

            // Return false to prevent the user from leaving the page
            return false;
        } else {    
            // Return true to allow the user to leave the page      
            return true;
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM