MyAppWeb.Router.Helpers.live_path/2 is undefined or private

I’m using version 0.6.0 of Phoenix Live view. I followed the documentation to do the installation: https://hexdocs.pm/phoenix_live_view/installation.html. The settings are exactly the same as in the documentation;

Some things are working well, but when trying to create a link with Routes.live_path the following error is displayed. function MyApp.Router.Helpers.live_path/2 is undefined or private.

<%= link('Click", to: Routes.live_path(@socket, MyApp.ModalLive), phx_click: "show-modal") %>

I tried to look for an answer, but I was unsuccessful.

1 Like

Do you have a live route definition in your router? Something like live "/modal", ModalLive ?

1 Like

You’re right @chrismccord , thank you very much. :grinning:

Since I spent a good half hour frustrated by this, I’m adding a comment for others who may find their way here.

I was also getting an undefined or private error for live_path even though I did have a live route. I had generated my project with --live so I knew LV was installed properly.

What I discovered is that if you have defined your live route with an action, like:

live "/", FooLive, :index

Then Routes.live_path will NOT be defined (but Routes.foo_path(socket, :index) will work). It took a long time for me to spot this. Removing the , :index from the router resulted in live_path being defined and operating as the docs outlined!

37 Likes

You just saved me HOURS of pain. Thank you!!!

6 Likes

Saved me a lot of time. Thanks!

3 Likes

I managed to resolve the live_path being undefined or private by also removing the , :indexfrom the router, it is subsequently defined.

What I’m trying to do is a live_redirect in a the live.html.leex where I want my navigation to move around pages in my web app. This works with linking to the PageLive generated by Live View generator used to generate the project in the first place – but it does not work with the subsequent Live View i generated for the resource Party. That Live View of course has the actions :index, :new and :edit.

I’m getting no function clause matching in [my project name]Web.PartyLive.Index.apply_action/3.

Most (all?) examples I’ve found do not show how to build up navigation. While I cannot figure out the above and realising that it may not make sense to a Live View pro, could anyone at least provide reference to a more complete example?

Thank you in advance.

1 Like

LiveViews are not like standard controllers. They don’t use actions. See Phoenix.LiveView — Phoenix LiveView v0.15.7 or The Lifecycle of a Phoenix LiveView for more info.

What you want to do here for simple navigation is

<%= live_redirect "Link text", to: Routes.live_path(@socket, AnotherLiveView) %>
3 Likes

You may want to review generated routes first:

mix phx.routes

In my case the route was inside scope "/admin", so I have to use Routes.admin_live_path(...)

4 Likes