Search code examples
laravellaravel-8laravel-livewire

How to get the current url with query string in Livewire


I'm using Laravel 8 with Livewire. I have created a search component with a lot of options, which are added to the query string.

Now I have the problem, that when I open the detail page of a result with <a href=, the query string is not saved anywhere and i cannot go back to the latest query.

Before I changed everything to Livewire, I've saved url()->current() to a session variable and opened that when going back. The problem with livewire is, even if the url shown is my current page with actual query params, current url returns livewire/message/nameofcomponent.

I have no idea how to go back from the detail page and get the latest query combinations.

Any suggestions?


Solution

  • One option to is to simply use history.back():

    <a href="javascript:window.history.back()">...</a>

    This should re-open the previous page including all query parameters.

    Alternatively, you can pass query parameters to the detail page as well and rebuild the route. But this comes with significant more work.