How to update the url correctly from a Live Component

Hi all,

I have a live component LC that renders a checkbox, when the checkbox changes its state, the component should perform a patch to the same page with an updated query string.

This is the handle_event executed when the checkbox changes:

def handle_event("checkbox-changed", params, socket) do
  updated_querystring = update_querystring(socket, params)
  {:noreply, push_patch(socket, to: ~p"<what-to-put-here>?#{updated_qs}")}

My question is: how to repace <what-to-put-here> with the current path?

I tried to pass the current path to the component as an attr, having:
push_patch(socket, to: ~p"#{socket.assigns.current_path}?#{updated_qs}")
But I got ** (ArgumentError) paths must begin with /, got: "##?#{updated_qs}".

I also tried URI.encode_query/2 but it doesn’t handle lists while sigil_p can.

Can I avoid using the sigil_p and still be able to encode a map as a url query string?


Thank you (as usual)