Skip to content

Navigation history #898

@code-distortion

Description

@code-distortion

Hi there,

When using $updatesQueryString = [...] so the url can be updated, I've noticed that navigations aren't added to the browser history.

If the user lands on a page with a Livewire component, interacts with the component and changes the url a few times, and then clicks "back" in their browser - they're taken to the page before the component page instead of the previous state on the same page.

I'd like to suggest that history.pushState() is used instead of history.replaceState() when navigating.

The documentation for this feature mentions that this is useful when the user hits the back button so I think it's the desired behaviour.

https://laravel-livewire.com/docs/properties#update-query-string

Some further changes would also need to be made to handle the popstate event - so the content on the page is updated.

A possible conflict could occur where both Livewire and the website itself wants to handle this popstate. Some details could be added to the state data so Livewire knows to ignore states it didn't push, but the developer using Livewire would need to be aware about Livewire's states if they also want to handle them.

What do you think of this idea?

I originally posted this on the Livewire forums and @xxdalexx suggested looking at Turbolinks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions