Here is how I solved it in my app:
-
I store the
params
inhandle_params
as part of the assigns:def handle_params(params, url, socket) do # You could store the params as is but I like to store # only what has been parsed/validated. params = parse_params(params) {:noreply, assign(socket, :params, params) end
-
Create a helper called
self_path
:def self_path(socket, action, extra) do Routes.live_path(socket, __MODULE__, action, Enum.into(extra, socket.assign.params)) end
-
Now I do:
push_path(socket, to: self_path(socket, :search, %{"sort_by" => "foo"}))