Replacing Turbolinks.Location.prototype.isHTML with hotwiredTurbo.Location.prototype.isHTML doesn’t work.
Probably due the fact it’s imported as a module right now instead of a script.
Probably I miss something trivial regarding JavaScript modules (can I compile it to a script?) and how I can get Turbo Drive to work with php by modifying the isHTML prototype.
I had a similar problem getting .aspx extensions to work. This snippet of code below seems to be working for me. You should be able to replace aspx with php, and be good to go. So far, I haven’t encountered problems with query strings. It looks like they should just work.
let isHtml = function (testing) {
let components = testing.pathname.split("/").slice(1);
let lastPathComponent = components.slice(-1)[0];
let extension = (lastPathComponent.match(/\.[^.]*$/) || [])[0] || "";
return location.origin === testing.origin && !!extension.match(/^(?:|\.(?:htm|html|xhtml|aspx))$/)
}
isHtml = isHtml.bind(Turbo.navigator.adapter.session);
Turbo.navigator.adapter.session.locationIsVisitable = isHtml;
Absolutely. As a heads up, I pushed this change over to another test site of mine, and it didn’t work right off. That site was running “beta.2”. Upgrading it to “beta.4” was all I needed in order to get that site working.
Finally got the time to get to work on this. @bteller I tried to implement your example, with aspx changed to php. However it doesn’t seem to work or get triggered on a navigation.
Any tips on how to get the current Turbo release to work with plain PHP are welcome.
The url format I use is: index.php?page=1, index.php?page=2.
Sadly, the source has been changed again and it is no longer possible to access the internals and override the isHTML function as I’d originally described. There is a GitHub issue, Override isHTML or locationIsVisitable? · Issue #185 · hotwired/turbo (github.com), but it is still open. It appears the only options are to fork the repository and override it in code, or manipulate the bundled production version of the script and override it there. Neither are great solutions. I’d prefer the Turbo team add an override check to the top of their isHTML function and allow us to override it in the fashion suggested below. In that way, it doesn’t matter how they refactor the code or where they move that function too, we can always override the internals.