turbolinks / turbolinks-classic

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

page:before-change not triggered on page restore #609

Closed itay-grudev closed 8 years ago

itay-grudev commented 9 years ago

According to your documentation the page:before-change event should be triggered when restoring a page (going back for example), but that is not the case.

Thibaut commented 8 years ago

This is intended, because popstate events are not preventable (unlike normal visits). Also, when the popstate event fires, the URL has already changed, so firing page:before-change at that time would lead to inconsistent behavior.

What are you using the event for?

itay-grudev commented 8 years ago

I needed to update something if the user goes back. You could create an event that is invoked in both cases, and explicitly state that it can't be prevented and document the inconsistencies. It would still be useful.

Thibaut commented 8 years ago

Have you tried using page:before-unload? It fires before the page changes (including on partial replacement).

itay-grudev commented 8 years ago

I tried many solutions and I ultimately gave up. I did tried before-unload, but as far as I remember it wasn't invoked on going back or it reported wrong URL. I don't really remember, but it didn't do the job.

Thibaut commented 8 years ago

It is invoked on history back/forward. What URL did you expect it to report? How are you reading the URL?

itay-grudev commented 8 years ago

I ultimately used a variable to store the previous page loaded and I bypassed the problem. Thank you for your time and will to help, but this was a month ago and I really don't remember.