Clicking “back” in the browser disables my javascript code if I'm using Turbolinks in Rails

后端 未结 4 1056
孤街浪徒
孤街浪徒 2020-12-14 19:42

Well, as the title says more or less. I\'m using the gem Turbolinks in my Rails application and I\'m having a bit of a problem with the \"browser back\"-button. My javascrip

4条回答
  •  醉梦人生
    2020-12-14 19:50

    Two solutions for Turbolinks Classic:

    Set the cache to 0 so that no pages are cached using HTML5 History.

    Turbolinks.pagesCached(0);
    

    Another solution is to listen to "page:restore" event and call your initialization method. This latter solution is more performant.

    document.addEventListener("page:restore", function() {
      app.init();
    });
    

提交回复
热议问题