PhoenixMountable.Routes (PhoenixMountable v0.2.1)

Copy Markdown View Source

The macros available inside PhoenixMountable.Definition.routes/1.

They mirror Phoenix.Router and Phoenix.LiveView.Router, with paths relative to the mount path. The mount macro turns them into ordinary routes of the host router.

routes do
  get "/export", MyLib.ExportController, :csv
  forward "/api", MyLib.API.Router

  scope "/admin" do
    pipe_through :admin
    live "/settings", MyLib.SettingsLive, :edit
  end

  live_session :public, host_on_mount: false do
    live "/share/:token", MyLib.ShareLive, :show
  end

  live_session :default, on_mount: [MyLib.Auth] do
    live "/", MyLib.HomeLive, :index
  end
end

Live routes outside a live_session belong to the :default session. A live session's routes must be declared together.

Route helpers are named after the mount: a route with as: :export gets the helper <mount name>_export_path, and routes without :as share the mount's name.

Summary

Functions

A DELETE route to a controller or plug. See Phoenix.Router.delete/4.

Forwards requests under path to a plug, such as a router of the library's API. See Phoenix.Router.forward/4.

A GET route to a controller or plug. See Phoenix.Router.get/4.

A HEAD route to a controller or plug. See Phoenix.Router.head/4.

A live session of the library.

A OPTIONS route to a controller or plug. See Phoenix.Router.options/4.

A PATCH route to a controller or plug. See Phoenix.Router.patch/4.

Pipes the routes of the scope through pipelines of the library (PhoenixMountable.Definition.pipeline/2) or module plugs.

A POST route to a controller or plug. See Phoenix.Router.post/4.

A PUT route to a controller or plug. See Phoenix.Router.put/4.

Groups routes under a path. Takes :pipe_through as an option, or call pipe_through/1 inside.

Functions

delete(path, plug, plug_opts, opts \\ [])

(macro)

A DELETE route to a controller or plug. See Phoenix.Router.delete/4.

forward(path, plug, plug_opts \\ [], opts \\ [])

(macro)

Forwards requests under path to a plug, such as a router of the library's API. See Phoenix.Router.forward/4.

get(path, plug, plug_opts, opts \\ [])

(macro)

A GET route to a controller or plug. See Phoenix.Router.get/4.

head(path, plug, plug_opts, opts \\ [])

(macro)

A HEAD route to a controller or plug. See Phoenix.Router.head/4.

live(path, live_view, action \\ nil, opts \\ [])

(macro)

A LiveView route. See Phoenix.LiveView.Router.live/4.

live_session(name, opts \\ [], list)

(macro)

A live session of the library.

The host's live session is named after the mount: :default becomes the mount name, any other session <mount name>_<session>.

Options

  • :on_mount — hooks of this session, run after the library's.
  • :host_on_mount — whether the host's :on_mount hooks run. Defaults to true. Use false for public pages, which the host's authentication hooks would otherwise guard.
  • :root_layout — overrides the library's root layout.
  • :layout — the LiveView layout of the session.

options(path, plug, plug_opts, opts \\ [])

(macro)

A OPTIONS route to a controller or plug. See Phoenix.Router.options/4.

patch(path, plug, plug_opts, opts \\ [])

(macro)

A PATCH route to a controller or plug. See Phoenix.Router.patch/4.

pipe_through(pipes)

(macro)

Pipes the routes of the scope through pipelines of the library (PhoenixMountable.Definition.pipeline/2) or module plugs.

post(path, plug, plug_opts, opts \\ [])

(macro)

A POST route to a controller or plug. See Phoenix.Router.post/4.

put(path, plug, plug_opts, opts \\ [])

(macro)

A PUT route to a controller or plug. See Phoenix.Router.put/4.

scope(path, opts \\ [], list)

(macro)

Groups routes under a path. Takes :pipe_through as an option, or call pipe_through/1 inside.