History navigation

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.

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.

You will probably be better off to make a github issue for this, it will get a lot more traction there. Currently, at least this is the way I’ve come to personally view it, discussions in github issues is a better place to figure out how to make livewire better and the discussions here are how to work with what’s currently available. More and more it just looks like a support forum. I’m not saying that’s how it should be or it shouldn’t change, it’s just been my experience here and how the current user base uses each. I think I’ve seen two, maybe three, pr’s stem from discussions here. One being when the creator was actually active here.

That said, livewire has plug and play functionality with turbolinks, and I think the query string changing becomes apart of the history when using it. The docs used to say something to the effect there were plans to build better page transitions and use turbolinks for now. Now it just says use turbolinks. It could be that the history stuff was just kinda forgotten about with the transitions idea, or it was made that way to work better with turbolinks, I couldn’t tell you, I’m just speculating.

Hi @xxdalexx, thanks for the feedback. I haven’t used Turbolinks before so I’m glad you mentioned it.

I’ve posted an issue on github https://github.com/livewire/livewire/issues/898 if anybody would like to follow this there.