Clarity.Router (Clarity v0.5.1)

Copy Markdown View Source

Router for the Clarity LiveView application.

Summary

Functions

Defines an clarity route. It expects the path the clarity dashboard will be mounted at and a set of options.

Can be used to create a :browser pipeline easily if you don't have one.

Functions

clarity(path, opts \\ [])

(macro)

Defines an clarity route. It expects the path the clarity dashboard will be mounted at and a set of options.

Options

  • :live_socket_path - Optional override for the socket path. it must match the socket "/live", Phoenix.LiveView.Socket in your endpoint. Defaults to /live.

  • :on_mount - Optional list of hooks to attach to the mount lifecycle.

  • :session - Optional extra session map or MFA tuple to be merged with the session.

  • :live_session_name - Optional atom to name the live_session. Defaults to :clarity.

Examples

defmodule MyAppWeb.Router do
  use Phoenix.Router

  scope "/" do
    import Clarity.Router

    # Make sure you are piping through the browser pipeline
    # If you don't have one, see `clarity_browser_pipeline/1`
    pipe_through [:browser]

    clarity "/clarity"
  end
end

clarity_browser_pipeline(name \\ :browser)

(macro)

Can be used to create a :browser pipeline easily if you don't have one.

By default it is called :browser, but you can rename it by supplying an argument, for example:

defmodule MyAppWeb.Router do
  use Phoenix.Router

  import Clarity.Router
  clarity_browser_pipeline :something

  scope "/" do
    pipe_through [:something]
    clarity "/clarity"
  end
end