Skip to content

Commit 371e156

Browse files
committed
fix: allow prefixing the link paths
1 parent 80637ee commit 371e156

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

dev.exs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ defmodule DemoWeb.Router do
456456
use Phoenix.Router
457457
import Phoenix.LiveDashboard.Router
458458

459+
forward "/admin", DemoWeb.Router.Admin
460+
end
461+
462+
defmodule DemoWeb.Router.Admin do
463+
use Phoenix.Router
464+
import Phoenix.LiveDashboard.Router
465+
459466
pipeline :browser do
460467
plug :fetch_session
461468
plug :protect_from_forgery
@@ -470,6 +477,8 @@ defmodule DemoWeb.Router do
470477
get "/hello/:name", DemoWeb.PageController, :hello
471478

472479
live_dashboard("/dashboard",
480+
live_socket_path: "/live",
481+
path_prefix: "/admin",
473482
env_keys: ["USER", "ROOTDIR"],
474483
metrics: DemoWeb.Telemetry,
475484
metrics_history: {DemoWeb.History, :data, []},
@@ -518,7 +527,7 @@ defmodule DemoWeb.Endpoint do
518527
same_site: "Lax"
519528
]
520529

521-
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
530+
socket "/admin/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
522531
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
523532

524533
plug Phoenix.LiveReloader

lib/phoenix/live_dashboard/page_builder.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
9696
9797
We currently support `card/1`, `fields_card/1`, `row/1`,
9898
`shared_usage_card/1`, and `usage_card/1`;
99-
and the live components `live_layered_graph/1`, `live_nav_bar/1`,
99+
and the live components `live_layered_graph/1`, `live_nav_bar/1`,
100100
and `live_table/1`.
101101
102102
## Helpers
@@ -956,7 +956,9 @@ defmodule Phoenix.LiveDashboard.PageBuilder do
956956
def live_dashboard_path(socket, route, node, old_params, new_params) when is_atom(node) do
957957
if function_exported?(socket.router, :__live_dashboard_prefix__, 0) do
958958
new_params = for {key, val} <- new_params, key not in ~w(page node), do: {key, val}
959-
prefix = socket.router.__live_dashboard_prefix__()
959+
prefix = socket.router.__live_dashboard_prefix__() |> dbg()
960+
# broken due to redirecting in a loop
961+
prefix = socket.router.__live_dashboard_path_prefix__() |> dbg()
960962

961963
path =
962964
if node == node() and is_nil(old_params["node"]) do

lib/phoenix/live_dashboard/router.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ defmodule Phoenix.LiveDashboard.Router do
9797
opts
9898
end
9999

100+
route_path_prefix = Keyword.get(opts, :path_prefix, "") <> path
101+
100102
scope =
101103
quote bind_quoted: binding() do
102104
scope path, alias: false, as: false do
@@ -126,7 +128,9 @@ defmodule Phoenix.LiveDashboard.Router do
126128

127129
unless Module.get_attribute(__MODULE__, :live_dashboard_prefix) do
128130
@live_dashboard_prefix Phoenix.Router.scoped_path(__MODULE__, path)
131+
@live_dashboard_path_prefix Phoenix.Router.scoped_path(__MODULE__, route_path_prefix)
129132
def __live_dashboard_prefix__, do: @live_dashboard_prefix
133+
def __live_dashboard_path_prefix__, do: @live_dashboard_path_prefix
130134
end
131135
end
132136
else

0 commit comments

Comments
 (0)