I’m developing a Hex package that provides a set of LiveView routes mounted from the router via live '/path', LiveViewName, session: [:blah]
. This package is then meant to be included in another Phoenix app. That app’s router can then forward requests to the Hex package’s paths, including the live mounted paths.
The hex package’s router looks like this:
defmodule RailwayUiWeb.Router do
use RailwayUiWeb, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug Phoenix.LiveView.Flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
scope "/", RailwayUiWeb do
pipe_through :browser
get "/", PageController, :index
live "/published_messages", PublishedMessageLive.Index, session: [:current_user_uuid]
live "/consumed_messages", ConsumedMessageLive.Index, session: [:current_user_uuid]
end
end
And the calling application’s router forwards requests like this:
scope path: "/admin", as: :admin do
forward("/railway-ipc", RailwayUiWeb.Router, namespace: "admin/railway-ipc")
end
Route forwarding is working in that the pages provided by the package do render when a user visits /admin/raiwlay-ipc/published_messages
, for example. But the live view then crashes with the message:
(ArgumentError) cannot invoke handle_params nor live_redirect/live_link to \"http://localhost:4000/admin/railway-ipc/published_messages\" because it isn't defined in RailwayUiWeb.Router\n (phoenix_live_view) lib/phoenix_live_view/utils.ex:135
When running the hex package as a standalone phoenix app, the live views render and run just fine.
Is there some reason why using forward
to forward to paths that are mounted in the destination router via live '/path'
wouldn’t work?