Search code examples
jqueryruby-on-railshistoryturbolinkswistia

How to fix first page with Rails' Turbolinks and Wistia's Fresh Url


When using Wistia's Fresh Url plugin, Turbolinks doesn't work on the first page. For example, if you navigate one page away and click the back button in the browser, the url with change but the page won't actually change at all. Once you navigate two pages away, though, Turbolinks starts working again.


Solution

  • Fresh Url uses window.history.replaceState() to update the url once it's finished, and turbolinks: true needs to be set.

    So, you have to add it to Fresh Url's FreshUrl.prototype.allReadyCallback() to be something like...

    FreshUrl.prototype.allReadyCallback = function() {
        return window.history.replaceState({ turbolinks: true }, "", FreshUrl.cleanUrl());
    };