簡體   English   中英

在ionic3中使用延遲加載的全局導航提供程序是否不好?

[英]Is it bad practice to use a global navigation provider in ionic3 with lazy loading?

我正在使用全局提供程序通過將導航控制器從頁面傳遞到provider方法來打開頁面。 還有其他更好的方法嗎?

主要目的是不重復自己。 我在globalProvider.ts中使用的打開頁面方法如下。 currentActive頁面存儲在提供程序的變量中,以防用戶登錄到應用程序,他將被重定向到最后一個活動頁面(currentActive)

globalProvider.ts

  openPage(navCtrl, page, params, setActive = true) {
    this.showLoading();
    if (setActive) {
      this.currentActive = { root: page, params: params };
    } else {
      this.currentActive = { root: 'HomePage', params: null };
    }
    navCtrl.setRoot(page, params).then(res => {
      if (!res) {
        this.showError('Please login to view page!');
        navCtrl.setRoot('LoginPage', {
          activePage: this.currentActive.root
        }).then(res => {
          this.hideLoading();
        }).catch(err => {
          this.hideLoading();
        });
      }
      this.hideLoading();

    }).catch(error => {
      this.hideLoading();
    });
  }

我認為這種做法沒有什么壞處。 我也做了類似的邏輯,以避免在每個頁面中重復執行show加載和hide加載邏輯。

但是,我還保留了另一個參數 ,以幫助我確定是應將頁面設置為root還是應將其壓入當前堆棧。

這也有助於我從中心位置跟蹤頁面視圖以進行分析。

暫無
暫無

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

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