Live view post route error - no route found for POST / (TestWeb.Router)

Hey guys, I’m a beginner in liveview. I’ve a problem, i don’t know what’s the matter.

Here my page_live.ex

defmodule TestWeb.PageLive do
  use TestWeb, :live_view

  alias Test.Checkouts
  alias Test.Checkouts.Checkout

  @impl true
  def mount(_params, _session, socket) do
    {:ok,
     socket |> assign(changeset: Checkouts.change_checkout(%Checkout{}),
                      checkout: nil, intent: nil)
    }
  end

  def handle_event("submit", params, socket) do
    IO.inspect params
    {:noreply, socket}
  end
end

and my page_live.html.leex

<%= f = form_for @changeset, "#", [phx_submit: "submit"] %>
<input type = "text" name= "nom">
  <button type="submit">submit</button>
</form>

When I submit my form, I always have this error

Phoenix.Router.NoRouteError at POST /
no route found for POST / (TestWeb.Router)

Help me guys!!

Thanks

I think the problem must be elsewhere. Your code looks like it should work and when I copy it into a new Phoenix project and submit the form the event is handled as expected.

@joshdcuneo , so you think the problem is in my config or my app!!?

It’s tricky to say without being able to see it. If you have a git repo you can share I could have a look for you.

check your javascript console. Maybe something went wrong and the LiveView client did not kick in. It looks like the form was submitted the old way.

1 Like

@derek-zhou Okay, i’ll take a look at that!! Thanks

@derek-zhou @joshdcuneo I found the problem
@derek-zhou You were right, i imported alpinejs like that:import "alpinejs", this is correct but alpinejs was not yet added to the dependency.

Thanks guy

1 Like