Problem in LiveView redirect to LiveView Controller without refresh (server side)

Hi, I have problem in LiveView redirect to LiveView Controller without refresh (server side). I used push_redirect in normal LiveView like this code and it works but I want to redirect to other LiveView Controller and I don’t know how!!

redirect to other LiveView which I did:

def handle_event("go_to_categories", _value, socket) do
      {
         :noreply, 
         push_redirect(socket, to: Routes.live_path(socket, Categories))
      }
end

now I want to redirect to categories router instead of Live path

defmodule ErfanWeb.PageController do
  use ErfanWeb, :controller
  import Phoenix.LiveView.Controller
  
  def index(conn, _params) do
    live_render(conn, ErfanWeb.Live.Index , session: %{})
  end

  def categories(conn, _params) do
    live_render(conn, ErfanWeb.Live.Categories , session: %{})
  end
end

it is important don’t redirect with refresh

thanks

Not possible. Your only option to redirect from controller <=> LV is redirect/2. If you want to support live navigation via push_redirect you need convert your controller to a LV. There are very few reasons to use live_render from the controller.

1 Like

yes thanks, but how can I call my controller function in LV again to use live_render, controller loads LV once a time I think !

do you have an example of live view controller in real project, I think I should just use LV instead of this and where is controller used? when we should use LV Anyway!


and I have 1 question more, is there differences between client redirect like live link and server side like push_redirect in speed ?

Thank you.

I’m not sure what a live view controller is but from a live view you can call a controller action. Take a look at this https://hexdocs.pm/phoenix_live_view/form-bindings.html#submitting-the-form-action-over-http