PhoenixDatastar.RouteRegistry (PhoenixDatastar v0.1.14)

Copy Markdown View Source

Runtime route lookup helpers for PhoenixDatastar session-aware routing.

This module matches request paths against the route metadata compiled by PhoenixDatastar.Router.datastar/3. Each router that uses datastar/3 generates a __phoenix_datastar_routes__/0 function at compile time, which this module reads at runtime.

Used internally by PhoenixDatastar.NavPlug to resolve navigation targets and verify session membership during soft navigation.

Summary

Functions

Matches a request path against registered Datastar routes.

Returns the datastar_session name for a matched route, or nil.

Types

route_match()

@type route_match() :: %{datastar: map(), path_params: map()} | nil

Functions

match(router, method, path, host \\ "localhost")

@spec match(module(), String.t(), String.t(), String.t()) :: route_match()

Matches a request path against registered Datastar routes.

Returns a map with :datastar (the route metadata including :view, :session_name, :root_selector, etc.) and :path_params (extracted dynamic segments), or nil if no route matches.

The method and host parameters are accepted for future use but are currently ignored — all registered routes are matched regardless.

session_name(router, method, path, host \\ "localhost")

@spec session_name(module(), String.t(), String.t(), String.t()) :: atom() | nil

Returns the datastar_session name for a matched route, or nil.

Convenience wrapper around match/4 that extracts just the session name.