Routes.somepath_path() undefined when using it in a Liveview rendered in the Root layout

I’ve started to experiment with different ways to build my Web app using Liveview, and in the root layout I have <%= live_render(@conn, MyAppWeb.ThermLive) %> to wrap everything I want to keep the sate between different LiveViews.
But when in the leex file I try to use <%= live_redirect "New Post", to: Routes.post_index_path(@socket, :new) %> I get an error: function Routes.post_index_path/2 is undefined (module Routes is not available).
From any other Liveview that is served directly from my router the same live_redirect works.
So, I’m lost regarding this Routes availability, specially because I though it was always available on any template.
How can I make it available for that Liveview rendered in the Root layout and not served in the Router?

Check that you have alias ExampleWeb.Router.Helpers, as: Routes in your view macros (view, live_view, live_component) inside the example_web.ex file.

This is assuming you are using them like so: use ExampleWeb, :live_view

1 Like

Damm copy paste from different sources to save some time…
I had checked the example_web.ex file, that was why I was lost. But now when going through your answer, I looked into my view…damm, I had: use Phoenix.LiveView, not use ExampleWeb, :live_view in this view.
Thank you so much for all the details @sfusato!

1 Like