-1

My SPA based on livewire is not loading javascript events after second page rendering: For example, two cases :

  1. First page refresh in dashboard loads the charts plugin. After I render some other page and come back to dashboard, the chart does not load again.

  2. I refresh the page, my menus in sidebar are collapsed. After I render some other page, they do not appear collapsed.

I'm using Turbolinks with Livewire on Laravel 8.

Thank you in advance.

2 Answers2

1
...
    @livewireScripts
    <script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks@v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false"></script>
</body>
Nashwan
  • 311
  • 4
  • 13
1

I had a similar problem, for me it did not work because I put the JS code into a window.onload function but when I removed the function, the inner code executed twice so I placed the inner code into a separate file and imported it and it works. Try putting the Charts initialization in a separate file.

Else have a look @ this: https://github.com/livewire/livewire/issues/1022

Emmanuel
  • 161
  • 5
  • 1
    Thank you so much. What worked for me was : I put document.addEventListener('turbolinks:load', function() { instead of document.addEventListener('DOMContentLoaded', function() { Hope it helps someone in future. – amitshrestha221 Nov 06 '20 at 05:05