phoenix_live_view v0.3.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. For example, the following would copy Plug's session current user ID and the remember_me value into the LiveView session:

    [: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: [:user_id]
    live "/dashboard", DashboardLive, layout: {MyApp.AlternativeView, "app.html"}
  end
end

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