【问题标题】:How to find F5 pressed and page is reloaded in Angular 6如何在Angular 6中找到按下F5并重新加载页面
【发布时间】:2019-12-12 07:17:11
【问题描述】:

我想知道浏览器是否在 app.component 中刷新而不使用路由器导航。如何实现这个功能

【问题讨论】:

    标签: angular refresh page-refresh


    【解决方案1】:

    您可以使用window.onbeforeunload

    window.onbeforeunload=()=>{
        this.myFunc();  // here you can do something like creating alert
    }
    

    【讨论】:

      【解决方案2】:

      试试这个:

      <div (window:beforeunload)="doSomething()"></div>
      

      看到这个帖子: Is there any lifecycle hook like window.onbeforeunload in Angular2?

      【讨论】:

        猜你喜欢
        • 2019-09-24
        • 2016-08-01
        • 2020-08-22
        • 2023-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-24
        • 1970-01-01
        相关资源
        最近更新 更多