我正在使用全局提供程序通过将导航 Controller 从页面传递到提供程序方法来打开页面。还有其他方法可以做得更好吗?
主要目标是不重复我自己。我在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();
});
}
最佳答案
我不认为这种做法有什么不好。我也做了类似的逻辑,以避免在每个页面中重复显示加载和隐藏加载逻辑。
但是,我还保留一个参数,以帮助我决定该页面是否应该设置为根或应该推送到当前堆栈。
这还可以帮助我从一个中心位置跟踪页面浏览量以进行分析。
关于javascript - 在 ionic3 中使用带有延迟加载的全局导航提供程序是一种不好的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49903285/