1

我是 angular2/ionic 的新手。我想做的是只允许对经过身份验证的页面进行访问。会有一些页面不需要认证,但95%需要认证。我希望装饰器beforeNavigate上有一个属性@Page,我可以在其中运行逻辑,如果登录页面未经过身份验证,则会将登录页面推送到导航堆栈。环顾四周,我似乎找不到类似的东西。这样做的正确方法是什么,而不必将其粘贴在每个构造函数或其他东西中?还有另一种方法可以解决这个问题吗?TIA。

请注意,这是 Angular2 / Ionic2 和打字稿(如果有的话)。

4

1 回答 1

1

您可以在此处找到有关Ionic 2 中查看生命周期挂钩的更多信息

Ionic 将一组视图生命周期钩子打包到 NavController 中。它们遵循四种事件处理程序模式:

 1. onPageLoaded works the same way as ngOnInit
 2. onPageWillEnter and onPageDidEnter are hooks that are available before and after the page in question becomes active
 3. onPageWillLeave and onPageDidLeave are hooks that are available before and after the page leaves the viewport
 4. onPageWillUnload and onPageDidUnload are hooks that are available before and after the page is removed from the DOM

就您而言,我认为您正在寻找的是onPageWillEnter

=============

编辑:

在 Ionic 2.0.0-beta.8 (2016-06-06) 上,Ionic Lifecycle Events 被重命名:

onPageLoaded renamed to ionViewLoaded
onPageWillEnter renamed to ionViewWillEnter
onPageDidEnter renamed to ionViewDidEnter
onPageWillLeave renamed to ionViewWillLeave
onPageDidLeave renamed to ionViewDidLeave
onPageWillUnload renamed to ionViewWillUnload
onPageDidUnload renamed to ionViewDidUnload

所以你需要使用的是:ionViewWillEnter

于 2016-06-09T19:27:56.580 回答