PhoenixKitWeb.Components.Core.PkLink (phoenix_kit v1.7.43)

Copy Markdown View Source

Provides prefix-aware link components for PhoenixKit navigation.

These components automatically apply the configured PhoenixKit URL prefix to paths, ensuring links work correctly regardless of the prefix configuration.

Why Use These Components?

PhoenixKit supports a configurable URL prefix (default: /phoenix_kit). Using these components instead of hardcoded paths ensures your links work correctly when the prefix changes.

Examples

# Instead of hardcoding:
<.link navigate="/phoenix_kit/dashboard">Dashboard</.link>

# Use pk_link for automatic prefix handling:
<.pk_link navigate="/dashboard">Dashboard</.pk_link>

# Works with all link types:
<.pk_link navigate="/admin/users">Users</.pk_link>
<.pk_link patch="/dashboard?tab=settings">Settings</.pk_link>
<.pk_link href="/api/export">Export</.pk_link>

Configuration

The URL prefix is configured in your application:

config :phoenix_kit, url_prefix: "/my_prefix"

Summary

Functions

Renders a link with automatic PhoenixKit URL prefix handling.

Renders a button-styled link with automatic PhoenixKit URL prefix handling.

Functions

pk_link(assigns)

Renders a link with automatic PhoenixKit URL prefix handling.

This component wraps Phoenix's <.link> and automatically prepends the configured PhoenixKit URL prefix to the path.

Attributes

  • navigate - The path for LiveView navigation (full page load within LiveView)
  • patch - The path for LiveView patch (updates URL without full navigation)
  • href - The path for standard HTTP navigation
  • class - CSS classes to apply
  • replace - When true, replaces browser history instead of pushing

Only one of navigate, patch, or href should be provided.

Examples

<.pk_link navigate="/dashboard">Dashboard</.pk_link>

<.pk_link navigate="/admin/users" class="btn btn-primary">
  Manage Users
</.pk_link>

<.pk_link patch="/settings" replace={true}>
  Settings
</.pk_link>

Attributes

  • navigate (:string) - Path for LiveView navigate. Defaults to nil.
  • patch (:string) - Path for LiveView patch. Defaults to nil.
  • href (:string) - Path for standard href. Defaults to nil.
  • class (:string) - Defaults to nil.
  • replace (:boolean) - Defaults to false.
  • Global attributes are accepted. Supports all globals plus: ["download", "hreflang", "referrerpolicy", "rel", "target", "type"].

Slots

  • inner_block (required)