@conn in LiveView .leex

Hello there, I wanna know how can I redirect the user form a LiveView using <%= link "view", to: Routes.upload_path(@conn, :show, upload.id) %> it gives me this error

** (exit) an exception was raised:
    ** (ArgumentError) assign @conn not available in eex template.

what am I missing and how should I approach such thing.

Thanks in advance!

If you don’t have access to a conn you can use your endpoint module instead.

<%= link "view", to: Routes.upload_path(MyApp.Endpoint, :show, upload.id) %>
2 Likes

Or the socket @socket. @conn and @socket might have more correct information about e.g. the used domain in reverse proxied settings.

3 Likes