Reverse routing for live routes: given a path can I get the module that's responsible for it?

Given live routes like these:

live "/projects/:id/config", ProjectsLive.Config
live "/projects/:id/config/calendar", ProjectsLive.Config.Calendar
live "/projects/:id/config/maintenance", ProjectsLive.Config.Tickets
live "/projects/:id/config/vendors", ProjectsLive.Config.Vendors

is there a way I can get the module name if I know the url path? Rails has this method: Rails.application.routes.recognize_path

Do you need it at runtime? If not, mix phx.routes works

Yes, I want it at runtime to return the user to a path that I save as a last known location.

May this help?

https://hexdocs.pm/phoenix/Phoenix.Router.html#route_info/4

iex> Phoenix.Router.route_info(AppWeb.Router, "GET", "/posts/123", "myhost")
%{
  log: :debug,
  path_params: %{"id" => "123"},
  pipe_through: [:browser],
  plug: AppWeb.PostController,
  plug_opts: :show,
  route: "/posts/:id",
}

iex> Phoenix.Router.route_info(MyRouter, "GET", "/not-exists", "myhost")
:error
1 Like