Can't redirect to LiveView marked with ':live' in Router

I am trying to redirect from one normal page back to the homepage using redirect. However, if the Live page is marked with :live in router.ex it does not working.

The error is

no action DreamUpWeb.HomeLive for DreamUpWeb.Router.Helpers.live_path/3. The following actions/clauses are supported:

    live_path(conn_or_endpoint, DreamUpWeb.BoardLive, params \\ [])
    live_path(conn_or_endpoint, DreamUpWeb.LobbyLive, params \\ [])
    live_path(conn_or_endpoint, DreamUpWeb.SetupLive, params \\ [])

router.ex:

    live "/", HomeLive, :live
    live "/lobby", LobbyLive
    live "/board", BoardLive
    live "/setup", SetupLive

redirect code in example_live.ex

{:noreply, redirect(socket, to: Routes.live_path(socket, DreamUpWeb.HomeLive, %{example: "example"}))}

If I remove :live it works as normal and does not seem to impact anything. I’m seeking some help to understand what :live actually accomplishes and why I cannot route to it using redirect.

Over here , :live is a live_action.

When an action is given, the generated route helpers are named after the LiveView itself (in the same way as for a controller).

Thus you should be able to define your route as:

Routes.home_path(socket, :live, %{example: "example"})
2 Likes

Thanks, this is what ended up working:

{:noreply, redirect(socket, to: Routes.home_path(socket, :index, %{error: "code"}))}