I started using live navigation
for the first time when I ran into trouble.
I have defined a live_session
like:
scope "/", AppWeb do
pipe_through :browser
live_session :courses do
live "/courses", Live.Courses, :index
live "/courses/:id", Live.Course, :show
end
end
And I want to navigate between /courses
and /courses/:id
using push_redirect/2
. And navigate between /courses/:id
and /courses/:id?activity=SOMENUMBER
using push_path/2
. In both cases I intend use the live_path
helper function, to get to target destination to navigate to.
This is where I donât fully understand what to do. How does live_path
work?
What arguments does it take? Does it take:
live_path(socket, live view module or action, params \\ [])
And how does Phoenix know whether a param is a param (e.g. id in /courses/:id
) or a query string (e.g. activity in /courses/:id?activity=SOMENUMBER
)?
I got the push_patch
to work.
socket = push_patch(socket, to: Routes.live_path(socket, __MODULE__, course_id, activity: activity_id))
{:noreply, assign(socket, :activity, activity)}
However, the push_redirect
does not work.
socket = push_redirect(socket, to: Routes.live_path(socket, :show, id))
{:noreply, socket}