Global in-session navigation endpoint.
Handles soft navigation between live views within the same datastar_session.
When a user navigates (via navigate/2 or <.ds_link>), this plug:
- Verifies the signed
nav_token(using Phoenix.Token-based signing). - Matches the target path against registered routes via
PhoenixDatastar.RouteRegistry. - Checks the target is a live view in the same
datastar_sessionas the source. - If valid: calls
Server.navigate/5to swap the view in the existing GenServer, pushing new HTML, signals, and apushStatescript through the SSE stream. A freshnav_tokenis issued for subsequent navigations. - If invalid: falls back to a full page reload via
window.location.
Expected route
post "/__datastar/nav", PhoenixDatastar.NavPlug, :navigate