Suggestion: Verified Routes with Subdomain Support

So verified paths is geniuenly one of the best features of a web framework I’ve ever seen in ~15 years, but I’ve encountered a place where it gets kinda tricky!

So imagine this router:

defmodule CoreWeb.Router do
  use CoreWeb, :router
  require PhoenixJSONAPI.Routing

  pipeline :browser do
    plug(:accepts, ["html"])
    plug(:fetch_session)
    plug(:fetch_live_flash)
    plug(:put_root_layout, html: {CoreWeb.Layouts, :root})
    plug(:protect_from_forgery)
    plug(:put_secure_browser_headers, CoreWeb.get_secure_browser_headers())
  end

  scope "/", host: "dashboard." do
    pipe_through([:browser])
    live("/", DashboardWeb.OverviewLive, :index)
  end

  scope "/", host: "admin." do
    pipe_through([:browser])
    live("/", AdminWeb.OverviewLive, :index)
  end
end

Pretty standard! This actually works and navigation is perfect. For example, inside admin_web/live/overview_live.html.heex if I reference ~p"/" it will be relative to the liveview’s domain.

However you may now realize that what if I want to go from dashboard overview to admin overview? Things become tricky, but not impossible. The annoyance however makes me wonder if the Phoenix team would be open to a change to verified routes: ~p"dashboard:/" or similar?

Related discussion: https://elixirforum.com/t/abandoned-proposal-for-multiple-p-sigils/57104

1 Like