您可以使用 获取路线列表YourProjectWeb.Router.__routes__()
。请注意,它是一个私有 API,可能会随着新的 phoenix 版本而改变。
然后,您可以:plug
根据%Phoenix.Router.Route
. 对于实时取景,这必须是Phoenix.LiveView.Plug
iex(18)> YourProjectWeb.Router.__routes__()
[
%Phoenix.Router.Route{
assigns: %{},
helper: "login",
host: nil,
kind: :match,
line: 2,
metadata: %{log: :debug},
path: "/login",
pipe_through: [:browser],
plug: YourProjectWeb.LoginController,
plug_opts: :index,
private: %{},
trailing_slash?: false,
verb: :get
},
%Phoenix.Router.Route{
assigns: %{},
helper: "settings",
host: nil,
kind: :match,
line: 39,
metadata: %{
log: :debug,
phoenix_live_view: {YourProjectWeb.SettingsLive, :index}
},
path: "/settings",
pipe_through: [:browser, :ensure_authenticated],
plug: Phoenix.LiveView.Plug,
plug_opts: :index,
private: %{
phoenix_live_view: {YourProjectWeb.SettingsLive,
[action: :index, router: YourProjectWeb.Router]}
},
trailing_slash?: false,
verb: :get
}
]