Router macros for PhoenixDatastar.
Usage
import PhoenixDatastar.Router
scope "/", MyAppWeb do
pipe_through :browser
datastar_session :default do
datastar "/counter", CounterStar
end
enddatastar/3 generates per-view routes:
GET /counter— renders the initial page viaPhoenixDatastar.PageControllerPOST /counter/_event/:event— handles events viaPhoenixDatastar.Plug
For live views, a global SSE stream endpoint (PhoenixDatastar.StreamPlug) and
a navigation endpoint (PhoenixDatastar.NavPlug) must also be added to the router.
See the README for the full setup.
Summary
Functions
Defines routes for a PhoenixDatastar view.
Groups datastar routes under shared stream/navigation behavior.
Functions
Defines routes for a PhoenixDatastar view.
The macro auto-detects whether the view is stateless (use PhoenixDatastar) or
live (use PhoenixDatastar, :live) and generates appropriate routes.
Options
:html_module- The Phoenix HTML module to use for rendering the mount template. Defaults toApplication.get_env(:phoenix_datastar, :html_module).
Groups datastar routes under shared stream/navigation behavior.
Routes within a datastar_session block are registered in the
PhoenixDatastar.RouteRegistry for soft navigation matching. When a user
navigates between views in the same session, the existing SSE connection
is reused and the view is swapped in-place without a full page reload.
Soft navigation only works between live views (use PhoenixDatastar, :live)
within the same session. Stateless views always trigger a full page reload.
Options
:root_selector- CSS selector for the container element patched during soft navigation. Defaults to"#app".:stream_guard- MFA tuple{Module, :function}stored as route metadata. Reserved for future use — not currently enforced byStreamPlugorNavPlug. Use pipeline plugs for authorization instead.:nav_guard- MFA tuple{Module, :function}stored as route metadata. Defaults to:stream_guard. Reserved for future use — not currently enforced.