如何检测在angularjs单页应用程序页面刷新没有路由的配置? [英] How can I detect a page refresh in an angularjs single page application without configuring routes?

查看:183
本文介绍了如何检测在angularjs单页应用程序页面刷新没有路由的配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to detect a page refresh event in my single page application.

推荐答案

您不能肯定,因为浏览器页面刷新等同于退出应用程序,然后再次打开它。

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.

在app.run()块注入窗口的依赖,并添加:

In the app.run() block inject 'window' dependency and add:

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

和$ routeChangeStart事件

and on $routeChangeStart event

$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 ....

我希望这有助于。

这篇关于如何检测在angularjs单页应用程序页面刷新没有路由的配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆