简体   繁体   English

如何在不配置路由的情况下检测angularjs单页面应用程序中的页面刷新?

[英]How can I detect a page refresh in an angularjs single page application without configuring routes?

我需要在单页面应用程序中检测页面刷新事件。

You can't for sure, because a browser page refresh is equivalent to exiting the app then opening it again. 您无法确定,因为浏览器页面刷新等同于退出应用程序然后再次打开它。

What you can do is detect the page exit event and the app open event. 您可以做的是检测页面退出事件和应用程序打开事件。

In the app.run() block inject 'window' dependency and add: 在app.run()块中注入'window'依赖项并添加:

window.onbeforeunload = function () {
   // handle the exit event
};

and on $routeChangeStart event 和$ routeChangeStart事件

$rootScope.$on('$routeChangeStart', function (event, next, current) {
  if (!current) {
    // handle session start event
  }
});

And if definitely you need to link these two events it has to be on the backend/server side .... 如果肯定你需要链接这两个事件,它必须在后端/服务器端....

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM