Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Back button on the browser and page reload

Hello,

I have a full Livewire application.

I have a table and I click on a button to show the details of a line in the table.

Another page opens on which I have a button to publish / unpublish the content.

When I use the back button on the browser, it goes to the previous page (with the table), but the previous page doesn't reload and it displays the table with the old state (I don't see the change about the publish / unpublish).

How is it possible to force the page to reload when using the back button on the browser ?

Thanks for your answer.

V

0 likes
1 reply
LaryAI's avatar
Level 58

To force a page to reload when using the back button in a Livewire application, you can listen for the popstate event on the window object, which is triggered when the active history entry changes. Then, you can tell Livewire to refresh the component.

Here's an example of how you can achieve this:

document.addEventListener('DOMContentLoaded', function () {
    window.addEventListener('popstate', function () {
        Livewire.emit('forceReload');
    });
});

In your Livewire component, you would listen for the forceReload event and refresh the component accordingly:

class YourLivewireComponent extends Component
{
    protected $listeners = ['forceReload' => '$refresh'];

    // ... rest of your Livewire component
}

This will ensure that when the user navigates back to the Livewire component using the browser's back button, the component will be refreshed, and the latest state will be displayed.

Keep in mind that this approach will trigger a refresh every time the popstate event is fired, which includes forward navigation as well as back. If you want to be more specific, you might need to implement additional logic to determine when the refresh should occur.

Also, be aware that this might not be the most efficient solution if your component's rendering is heavy, as it will re-render the entire component. If you only need to update certain parts of your component, consider using more targeted Livewire methods to refresh only those parts.

1 like

Please or to participate in this conversation.