Handling and retrieving query parameters in live view

How can I handle query parameters in a live view? I.e an url such as /books?category=drama&author=John

Router.ex

live "/books", BooksLive, :index
1 Like

You can find parameters here in the first argument: https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#c:mount/3

Ah okay, I was confusing the usage of handle_params. It is only triggered after push_patch thus I was never seeing the parameters.

Thanks!

You were correct, handle_params is called right before render. You can read about Phoenix.LiveView Life-cycle. If you do it on mount, then it will only handle the params when you mount the liveview, If you want it to be more dynamic on every patch, then put in handle_params and it will run after mount and every patch

3 Likes