Hi all
I want to reuse a full liveview on another page inside a modal.
It’s a complicated search UI with filters etc.
The idea is to provide the full UI as an alternative to a simple text based select component, if the user needs more complex filters.
This seemed like a perfect use case for a child liveview via live_render
.
It works very well, but only if I remove the handle_params/3
callback from the module.
If I include it, I get this error:
** (ArgumentError) cannot invoke handle_params/3 on AppWeb.Live.Library because it is not mounted nor accessed through the router live/3 macro
(phoenix_live_view 1.0.12) lib/phoenix_live_view/route.ex:26: Phoenix.LiveView.Route.live_link_info!/3
(phoenix_live_view 1.0.12) lib/phoenix_live_view/channel.ex:1209: Phoenix.LiveView.Channel.verified_mount/8
(phoenix_live_view 1.0.12) lib/phoenix_live_view/channel.ex:84: Phoenix.LiveView.Channel.handle_info/2
(stdlib 6.2.1) gen_server.erl:2345: :gen_server.try_handle_info/3
(stdlib 6.2.1) gen_server.erl:2433: :gen_server.handle_msg/6
(stdlib 6.2.1) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
I do not need the handle_params
callback when it’s rendered as a child liveview, but when rendered at the root I do need it. (The view has tabs which change the URL, but when rendered as a child liveview I disable those tabs)
Why can it not just ignore the callback when rendered as a child view? Why does it even try to invoke it?
How can I solve this?
I’m currently thinking about writing a macro which essentially duplicates my whole module except for handle_params
…
But there has to be a better solution, right?