Using with Turbolinks

onmount is a perfect fit with projects that use Turbolinks. You’ll notice that jQuery’s document ready event is not friendly for Turbolinks applications. You should call $.onmount() when Turbolinks changes pages.

Turbolinks v5

The event is turbolinks:load for Turbolinks 5. You will also need to teardown behaviors on turbolinks:before-cache (info).

$(document).on('ready turbolinks:load', function () { $.onmount() })
$(document).on('turbolinks:before-cache', function () { $.onmount.teardown() })

Discussion on this setup may be found here.

Turbolinks v2

The event is page:change For Turbolinks 2 and below.

$(document).on('ready page:change', function () { $.onmount() })
With React
Next: With Rails
    • onmount
    • Premise
    • API
    • Features
      • Idempotency
      • Performing cleanups
      • Unique IDs
      • Cancelling
      • Automatic observation
      • Role attributes
    • Testing
      • Testing
    • Integrations
      • With React
      • With Turbolinks
        • Turbolinks v5
        • Turbolinks v2
      • With Rails