# `PhoenixKit.Utils.Routes`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.120/lib/phoenix_kit/utils/routes.ex#L1)

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.

# `admin_path`

Returns a locale-aware admin path. For non-primary locales the locale
segment is always emitted. For the primary locale the shape follows
the site-wide `default_language_no_prefix` setting
(`Languages.default_language_no_prefix?/0`): prefixless when the
setting is on, prefixed when off.

Both URL shapes resolve at the router level — the admin route macros
declare `/:locale/admin/*` AND `/admin/*` scopes — so either shape is
routable. The two shapes share one `live_session :phoenix_kit_admin`,
so locale switching across them stays on the WebSocket
(`push_navigate`) without a full-page reload.

## Examples

    iex> Routes.admin_path("/admin/users", "uk")
    "/phoenix_kit/uk/admin/users"

    iex> Routes.admin_path("/admin/users", nil)
    "/phoenix_kit/admin/users"

Primary-locale shape depends on the `default_language_no_prefix`
setting (not shown as doctests because the result varies with
runtime state):

    # setting OFF (default)
    Routes.admin_path("/admin/users", "en") #=> "/phoenix_kit/en/admin/users"

    # setting ON
    Routes.admin_path("/admin/users", "en") #=> "/phoenix_kit/admin/users"

# `ai_path`

Returns the path to the AI endpoints page.

# `get_default_admin_locale`

Returns the default locale (base code) from the Languages module.

Extracts the base code from the default language (e.g., "en-US" becomes "en").
Falls back to "en" if no default language is configured.

## Examples

    iex> Routes.get_default_admin_locale()
    "en"

# `locale_aware_path`

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).

# `path`

# `phoenix_kit_app_base`

```elixir
@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"

# `url`

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.

# `url_prefix`

```elixir
@spec url_prefix() :: String.t()
```

Returns the configured PhoenixKit URL prefix.

## Examples

    iex> PhoenixKit.Utils.Routes.url_prefix()
    "/phoenix_kit"

---

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