turbolinks / turbolinks-classic

Classic version of Turbolinks. Now deprecated in favor of Turbolinks 5.
MIT License
3.54k stars 428 forks source link

Add option to skip pushState during Turbolinks.visit with new history option #652

Open rmm5t opened 8 years ago

rmm5t commented 8 years ago

I'd like to open up a discussion about the possibility of adding an option to Turbolinks.visit to allow for skipping any pushState changes during that particular request.

There are some cases where I'd like to use Turbolinks to load a new partial using a different URL resource than the current page, but after replacing the partial, I'd like to avoid changing the address bar, and more importantly, not change the browsers history for that request. There's also an alternative case where instead of just skipping the pushState call, I might prefer to issue a replaceState call for that particular Turbolinks.visit request.

If this is something that has a potential for being pulled in, I'm willing to investigate and work on a pull-request, but I wanted to get buy-in first.

Potential option name:

Example usage:

// Refresh the comments without changing the URL nor browser history
Turbolinks.visit(url, { change: ['comments'], history: false });

// Refresh the comments, change the address bar, but don't create a new browser history entry
Turbolinks.visit(url, { change: ['comments'], history: 'replaceState' });

// Good ol' regular usage. All being equal:
Turbolinks.visit(url, { change: ['comments'] });
Turbolinks.visit(url, { change: ['comments'], history: true });
Turbolinks.visit(url, { change: ['comments'], history: 'pushState' });
rmm5t commented 8 years ago

Looks like Turbolinks 5 implements this with an action option. For example:

Turbolinks.visit(url, { action: "replace" });