Resolves actual routes from parent application router.
Uses router introspection to automatically detect URL patterns, falling back to Settings configuration when introspection fails.
Resolution Priority
- Router Introspection - automatic detection from parent app router
- Settings override - manual configuration in PhoenixKit Settings
- Hardcoded fallback - default values
Usage
# Find path for specific plug module
RouteResolver.find_route(PhoenixKitWeb.Users.Registration)
# => "/users/register"
# Find content route by type
RouteResolver.find_content_route(:pages)
# => "/pages/:slug"
RouteResolver.find_content_route(:entity, "product")
# => "/products/:slug"
Summary
Functions
Checks if a content route (posts, entities, etc.) requires authentication.
Extracts URL prefix from a route pattern.
Finds route pattern by content type.
Finds index route for content type (list page without :slug).
Finds path for a specific plug module.
Gets router module with automatic discovery.
Returns all routes from the parent router.
Checks if a route requires authentication based on its on_mount hooks.
Functions
Checks if a content route (posts, entities, etc.) requires authentication.
Examples
content_route_requires_auth?(:posts)
# => false
content_route_requires_auth?(:entity, "product")
# => false
Extracts URL prefix from a route pattern.
Examples
extract_prefix("/pages/:slug")
# => "/pages"
extract_prefix("/content/*path")
# => "/content"
extract_prefix("/blog/posts/:id")
# => "/blog/posts"
Finds route pattern by content type.
Types
:pages- Finds routes that look like page routes (contain :slug and plug name contains "page"):posts- Finds routes that look like post routes (contain :slug and plug name contains "post"):entity- Finds routes matching entity name (singular or plural form)
Examples
find_content_route(:pages)
# => "/pages/:slug"
find_content_route(:posts)
# => "/posts/:slug"
find_content_route(:entity, "product")
# => "/products/:slug"
find_content_route(:entity, "page")
# => "/pages/:slug"
Finds index route for content type (list page without :slug).
Examples
find_index_route(:posts)
# => "/posts"
find_index_route(:entity, "page")
# => "/page" or "/pages"
find_index_route(:entity, "product")
# => "/products"
Finds path for a specific plug module.
Options
:verb- HTTP verb to match (default::get)
Examples
find_route(PhoenixKitWeb.Users.Registration)
# => "/users/register"
find_route(MyApp.SomeController, verb: :post)
# => "/some/path"
Gets router module with automatic discovery.
Resolution order:
config :phoenix_kit, router: MyAppWeb.Router- Via endpoint from
config :phoenix_kit, endpoint: MyAppWeb.Endpoint - Auto-discover from OTP applications (finds *Web.Router modules)
@spec get_routes() :: [map()]
Returns all routes from the parent router.
Returns empty list if router is not available.
Checks if a route requires authentication based on its on_mount hooks.
Returns true if the route uses authentication-requiring on_mount hooks:
:phoenix_kit_ensure_authenticated_scope:phoenix_kit_ensure_admin
Examples
route_requires_auth?(%{metadata: %{...}})
# => true/false
# Check by path pattern
route_requires_auth?("/posts")
# => true/false