How Turbolinks handles redirects
When you visit location /one
and the server redirects you to location /two
, you expect the browser’s address bar to display the redirected URL. However, Turbolinks makes requests using XMLHttpRequest
, which transparently follows redirects. There’s no way for Turbolinks to tell whether a request resulted in a redirect without additional cooperation from the server.
To work around this problem, Rails sends a Turbolinks-Location
header in response to a visit that was redirected using redirect_to
, and Turbolinks will replace the browser’s topmost history entry with the value provided. If for some reason you are performing redirects manually (so-to-speak, without using the redirect_to
helper method), then you'll have to take care of adding the header yourself.