2023-11-14 17:58:38 +08:00
|
|
|
function mountWithTurbolinks(app, target, callback = null) {
|
2023-11-10 02:17:51 +08:00
|
|
|
const originalHtml = document.querySelector(target).innerHTML;
|
|
|
|
|
2023-11-09 02:32:43 +08:00
|
|
|
document.addEventListener('turbolinks:before-cache', () => {
|
|
|
|
app.unmount();
|
2023-11-14 17:58:38 +08:00
|
|
|
if (document.querySelector(target)) {
|
|
|
|
document.querySelector(target).innerHTML = originalHtml;
|
|
|
|
}
|
|
|
|
if (callback) callback();
|
2023-11-09 02:32:43 +08:00
|
|
|
}, { once: true });
|
2023-11-10 02:17:51 +08:00
|
|
|
|
|
|
|
return app.mount(target);
|
2023-11-09 02:32:43 +08:00
|
|
|
}
|
|
|
|
|
2023-11-10 02:17:51 +08:00
|
|
|
export { mountWithTurbolinks };
|