Utility functions for working with PhoenixKit routes and URLs.
This module provides helpers for constructing URLs with the correct PhoenixKit prefix configured in the application.
Summary
Functions
Returns a locale-prefixed admin path, bypassing the reserved-path
locale stripping that path/2 applies.
Returns the path to the AI endpoints page.
Returns the default admin locale (base code).
Returns a locale-aware path using locale from assigns.
Gets the base module name for the parent application.
Returns a full url with preconfigured prefix.
Returns the configured PhoenixKit URL prefix.
Functions
Returns a locale-prefixed admin path, bypassing the reserved-path
locale stripping that path/2 applies.
Admin routes use a /:locale/admin/* scope, so they need locale
in the URL even though /admin is a reserved prefix.
Examples
iex> Routes.admin_path("/admin/users", "uk")
"/phoenix_kit/uk/admin/users"
iex> Routes.admin_path("/admin/users", nil)
"/phoenix_kit/admin/users"
Returns the path to the AI endpoints page.
Returns the default admin locale (base code).
This is the first language in the admin_languages setting list, extracted to its base code (e.g., "en-US" becomes "en").
Falls back to "en" if no admin languages are configured.
Examples
iex> Routes.get_default_admin_locale()
"en" # or "ko" if Korean is first in admin_languagesUse Case
This is used automatically in the on_mount hook to set current_locale
in socket assigns. LiveViews can then simply use:
locale = params["locale"] || socket.assigns[:current_locale]
Returns a locale-aware path using locale from assigns.
This function is specifically designed for use in component templates where the locale needs to be passed explicitly via assigns.
Prefers base locale code for URL generation (current_locale_base), falls back to extracting base from full dialect code (current_locale).
@spec phoenix_kit_app_base() :: String.t()
Gets the base module name for the parent application.
Reads from :phoenix_kit, :layouts_module config (e.g., MprojectWeb.Layouts -> MprojectWeb).
Examples
iex> PhoenixKit.Utils.Routes.phoenix_kit_app_base()
"MprojectWeb"
Returns a full url with preconfigured prefix.
This function first checks for a configured site URL in Settings, then automatically detects the correct URL from the running Phoenix application endpoint when possible, falling back to static configuration. This ensures that magic links and other email links work correctly in both development and production environments, with full control over the base URL through the Settings admin panel.
@spec url_prefix() :: String.t()
Returns the configured PhoenixKit URL prefix.
Examples
iex> PhoenixKit.Utils.Routes.url_prefix()
"/phoenix_kit"