Let say we have LiveView rendered from a router via live "/awesome", AwesomeLive.Index, :index
.
Now, in order to render it from a regular template or controller we need to use live_render/3
.
But that won't work, because: cannot invoke handle_params/3 on AwesomeLive.Index because it is not mounted nor accessed through the router live/3 macro
How to refactor handle_params/3
? Inside is a autogenerated code via phx.gen.live
@impl true
def handle_params(params, _url, socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
end
Inside the params
is :not_mounted_at_router
EDIT:
Not having handle_params/3
appears to break live_patch/2
or something and throw JavaScript error:
phoenix_live_view.js:1 Uncaught TypeError: Cannot read property 'el' of null
at e.value (phoenix_live_view.js:1)
at phoenix_live_view.js:1
at e.value (phoenix_live_view.js:1)
at e.value (phoenix_live_view.js:1)
at e.value (phoenix_live_view.js:1)
at phoenix_live_view.js:1
at phoenix_live_view.js:1
at Object.callback (phoenix_live_view.js:1)
at e.value (phoenix.js:1)
at phoenix.js:1
Versions:
- Erlang/OTP 23
- Elixir 1.10.3
- :phoenix, "1.5.1"
- :phoenix_live_view, "0.12.1"