phoenix_live_view v0.6.0 Phoenix.LiveView.Router View Source

Provides LiveView routing for Phoenix routers.

Link to this section Summary


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.


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.


  • :session - a map of strings keys and values to be merged into the session

  • :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;"}. See Phoenix.LiveView.live_render/3 for more information on examples.

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


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

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

    live "/thermostat", ThermostatLive
    live "/clock", ClockLive
    live "/dashboard", DashboardLive, layout: {MyApp.AlternativeView, "app.html"}

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