React | How to detect Page Refresh (F5)

后端 未结 4 1405
北海茫月
北海茫月 2020-12-03 10:57

I\'m using React js. I need to detect page refresh. When user hits refresh icon or press F5, I need to find out the event.

I tried with stackoverflow po

4条回答
  •  星月不相逢
    2020-12-03 11:19

    Unfortunately currently accepted answer cannot be more considered as acceptable since performance.navigation.type is deprecated

    The newest API for that is experimental ATM. As a workaround I can only suggest to save some value in redux (or whatever you use) store to indicate state after reload and on first route change update it to indicate that route was changed not because of refresh.

提交回复
热议问题