Q: React js - detect backbutton in reactjs don't work onbeforeunload, this code:
ComponentDidMount
     window.onbeforeunload = function(e) {
      return 'Are you sure you want to leave this page?  You will lose any unsaved data.';
       };

work with only update(F5, Ctrl + R, update) but don't work when click back button or backspace.

A: window.onbeforeunload will only be triggered if pressing the back button causes the browser to leave the page. If you are using hashes to track in-page state, then it's not going to do anything for you.
If that is the case, you should use window.onhashchange instead. If that's not the case, please provide more detail in your question.
