Heres how I do it.
- Define a liveview mount hook.
defmodule MyAppWebWeb.Hooks.DefaultHooks do
import Phoenix.Component
import Phoenix.LiveView
def on_mount(:default, _params, session, socket) do
socket = attach_hook(socket, :current_path_hook, :handle_params, &put_uri_hook/3)
{:cont, socket}
end
def put_uri_hook(_params, uri, socket), do: {:cont, assign(socket, uri: uri)}
end
- Call this in hook in your routes, then the @uri will be available in assigns in your liveview, you can pass it down your component as attribute.






















