使用 Ionic 框架在登录/注销时清除历史记录和重新加载页面 [英] Clear History and Reload Page on Login/Logout Using Ionic Framework
问题描述
我是使用 Ionic 开发移动应用程序的新手.在登录和注销时,我需要重新加载页面,以刷新数据,但是,$state.go('mainPage')
将用户带回视图而不重新加载 - 它背后的控制器永远不会被调用.
I am new to mobile application development with Ionic. On login and logout I need to reload the page, in order to refresh the data, however, $state.go('mainPage')
takes the user back to the view without reloading - the controller behind it is never invoked.
有没有办法清除历史记录并重新加载 Ionic 中的状态?
Is there a way to clear history and reload the state in Ionic?
推荐答案
欢迎使用框架!实际上,Ionic 中的路由由 ui-router 提供支持.您可能应该查看 这个以前的 SO 问题 找到几种不同的方法来实现这一点.
Welcome to the framework! Actually the routing in Ionic is powered by ui-router. You should probably check out this previous SO question to find a couple of different ways to accomplish this.
如果您只想重新加载状态,可以使用:
If you just want to reload the state you can use:
$state.go($state.current, {}, {reload: true});
如果您真的想重新加载页面(例如,您想重新引导所有内容),那么您可以使用:
If you actually want to reload the page (as in, you want to re-bootstrap everything) then you can use:
$window.location.reload(true)
祝你好运!
这篇关于使用 Ionic 框架在登录/注销时清除历史记录和重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!