Redirect with turbolinks from javascript

droptheplot picture droptheplot · Sep 4, 2014 · Viewed 7.8k times · Source

Is it possible to make window.location.replace or window.location.href work with turbolinks like it's a simple link?

Answer

MrYoshiji picture MrYoshiji · Sep 4, 2014

From the documentation: https://github.com/rails/turbolinks#triggering-a-turbolinks-visit-manually

You can use Turbolinks.visit(path) to go to a URL through Turbolinks.

You can also use redirect_to path, turbolinks: true (or turbolinks: :advance) in Rails to perform a redirect via Turbolinks.


This should work:

Turbolinks.visit('http://google.com')