Migrating a Rails app from using sprockets to webpack can contain a few small gotchas, getting Turbolinks back is one of them.
Normally we get Turbolinks for “free” in Rails apps, it comes set up out of the box. If running an older version of Rails, a
rails new will set up Turbolinks in the asset pipeline, a newer version will hook it up with webpack.
If you are migrating an existing app that used the asset pipeline to one that uses webpack, you don’t get turbolinks for free anymore. There are a couple of manual steps.
Install Turbolinks with Yarn
The first thing we need to do is use
yarn to install Turbolinks, not bundle.
yarn add turbolinks
This will pull in the appropriate package.
Since we don’t use bundle to manage Turbolinks anymore, we can remove it from our Gemfile
gem 'turbolinks'from your Gemfile
Tell our application about Turbolinks
Just like how
require("turbolinks").start();in your packfile will get Turbolinks running