# `PhoenixDatastar.NavPlug`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.2.0/lib/nav_plug.ex#L1)

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:

1. Verifies the signed `nav_token` (using Phoenix.Token-based signing).
2. Matches the target path against registered routes via `PhoenixDatastar.RouteRegistry`.
3. Checks the target is a live view in the same `datastar_session` as the source.
4. If valid: calls `Server.navigate/5` to swap the view in the existing GenServer,
   pushing new HTML, signals, and a `pushState` script through the SSE stream.
   A fresh `nav_token` is issued for subsequent navigations.
5. If invalid: falls back to a full page reload via `window.location`.

## Expected route

    post "/__datastar/nav", PhoenixDatastar.NavPlug, :navigate

---

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