Pax.Admin.Router (Pax v0.0.1-dev)

View Source

Provides functionality for mounting Pax.Admin sites in your router.

use Pax.Admin.Router

When you use Pax.Admin.Router the pax_admin/3 macro will be imported for use in your router. A module attribute called @pax_paths will also be defined. This attribute is used by Pax.Admin.Site to determine the path to a given admin site. It will be exposed with a __pax__/1 function that returns a map of site modules to paths when called with :paths.

Note: This must be done in your main Router, not in a Router that is forwarded from another router. This is currently a limitation of LiveView per https://github.com/phoenixframework/phoenix_live_view/issues/476.

Summary

Functions

Mounts a Pax.Admin.Site at the given path in your router.

Functions

pax_admin(path, site_mod, opts \\ [])

(macro)

Mounts a Pax.Admin.Site at the given path in your router.

This macro will define a live_session block that contains many Phoenix.LiveView.Router.live/4 calls to define endpoints for the admin site. If router helpers are enabled, then it will generate route helper names based on the Site module's name.

Options

  • :as - The name to use for the route helpers. Defaults to the underscored version of the Site module's name.

  • :root_layout - An optional root layout tuple for the initial HTTP render. Defaults to {Pax.Admin.Layouts, :root}.

  • :layout - An optional layout tuple for the Admin interface. Defaults to {Pax.Admin.Layouts, :admin}.

  • :on_mount - The optional list of hooks to attach to the mount lifecycle of each LiveView in the session. See Phoenix.LiveView.on_mount/1. Passing a single value is also accepted.

Examples

  scope "/", MyappWeb do
    pipe_through [:browser]

    pax_admin "/admin", MainAdmin.Site,
      as: :admin,
      on_mount: {MyAppWeb.AdminAuth, :ensure_user_is_admin}
    pax_admin "/public/admin", PublicAdmin.Site
  end