# `PhoenixDatastar.Router`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/router.ex#L1)

Router macros for PhoenixDatastar.

## Usage

    import PhoenixDatastar.Router

    scope "/", MyAppWeb do
      pipe_through :browser

      datastar_session :default do
        datastar "/counter", CounterStar
      end
    end

`datastar/3` generates per-view routes:
  - `GET /counter` — renders the initial page via `PhoenixDatastar.PageController`
  - `POST /counter/_event/:event` — handles events via `PhoenixDatastar.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.

# `datastar`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/router.ex#L94)
*macro* 

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 to `Application.get_env(:phoenix_datastar, :html_module)`.

# `datastar_session`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/router.ex#L61)
*macro* 

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 by `StreamPlug` or `NavPlug`.
    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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
