phoenix_live_view v0.1.0 Phoenix.LiveView.Router View Source

Provides LiveView routing for Phoenix routers.

Link to this section Summary

Functions

Defines a LiveView route.

Link to this section Functions

Link to this macro

live(path, live_view, opts \\ []) View Source (macro)

Defines a LiveView route.

Layout

When a layout isn't explicitly set, a default layout is inferred similar to controller actions. For example, the layout for the router MyAppWeb.Router would be inferred as MyAppWeb.LayoutView and would use the :app template.

Options

  • :session - the optional list of keys to pull out of the Plug connection session and into the LiveView session. The :path_params keys may also be provided to copy the plug path params into the session. Defaults to [:path_params]. For example, the following would copy the path params and Plug session current user ID into the LiveView session:

    [:path_params, :user_id, :remember_me]
  • :layout - the optional tuple for specifying a layout to render the LiveView. Defaults to {LayoutView, :app} where LayoutView is relative to your application's namespace.

  • :container - the optional tuple for the HTML tag and DOM attributes to be used for the LiveView container. For example: {:li, style: "color: blue;"}

  • :as - optionally configures the named helper. Defaults to :live.

Examples

defmodule MyApp.Router
  use Phoenix.Router
  import Phoenix.LiveView.Router

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

    live "/thermostat", ThermostatLive
    live "/clock", ClockLive, session: [:path_params, :user_id]
    live "/dashboard", DashboardLive, layout: {MyApp.AlternativeView, "app.html"}
  end
end

iex> MyApp.Router.Helpers.live_path(MyApp.Endpoint, MyApp.ThermostatLive)
"/thermostat"